背景过滤MRI图像

时间:2013-06-17 19:03:35

标签: matlab background filtering

我想使用形态学过滤掉我的图像,这样我就可以拥有主图像,但是,我生成的图像是非兼容类型。我应该如何使两个相同的图像类型来执行代码,或者我应该做什么呢?

info = dicominfo('MR000025.dcm');
>> Z = dicomread(info);
>> I=imadjust(Z,stretchlim(Z),[0 1]);
>>  figure, imshow(I)
>> background = imopen(I,strel('disk',10));
figure,imshow(background)
>> 

>> background = imopen(I,strel('disk',15));
>> figure,imshow(background)
>> figure, surf(double(background(1:8:end,1:8:end))),zlim([0 255]);
set(gca,'ydir','reverse');

>> I2 = I - background;
figure, imshow(I2)
>> I3 = imadjust(I2);
figure, imshow(I3);
>> level = graythresh(I3);
bw = im2bw(I3,level);
bw = bwareaopen(bw, 50);
figure, imshow(bw)
>> I4 = I - bw;
figure, imshow(I4)

Error using  - 
Integers can only be combined with integers of
the same class, or scalar doubles.

>> i=im2uint8(I);
>> i4=i-bw;
Error using  - 
Integers can only be combined with integers of
the same class, or scalar doubles.

>> i2=gray2ind(bw);
>> i3=i-i2;
>> figure, imshow(i3)
>> 

1 个答案:

答案 0 :(得分:1)

这是因为bw是一种逻辑类型。如果你添加:

bw = bwareaopen(bw, 50);
bw = uint8(255*bw);

你的错误会消失。但是代码可能无法正常工作......

相反,忽略上面。

试试这个:

I4 = I;
I4(bw)=0;

而不是

I4 = I - bw;

编辑:

注意到你正在使用graythresh,这意味着它是RGB启动所以上面需要调整:

I4 = I;
I4(repmat(bw,[1 1 3]))=0;