0

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

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)
>> 
4

1 回答 1

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;
于 2013-06-17T19:32:14.767 回答