我想用形态学过滤掉我的图像,这样我就可以得到主图像了,然而,我生成的图像是不兼容的类型。我应该如何让这两个镜像类型相同来执行代码,或者我应该怎么做呢?
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)
>> 发布于 2013-06-18 03:32:15
这是因为bw是一个逻辑类型。如果添加以下内容:
bw = bwareaopen(bw, 50);
bw = uint8(255*bw);你的错误将会消失。但代码可能不会像预期的那样工作。
相反,忽略上面的内容。
试试这个:
I4 = I;
I4(bw)=0;而不是
I4 = I - bw;编辑:
注意到你使用的是灰度阈值,这意味着它是RGB启动的,所以上面的代码需要调整:
I4 = I;
I4(repmat(bw,[1 1 3]))=0;https://stackoverflow.com/questions/17154872
复制相似问题