简体   繁体   English

RGB图像上重叠的二进制图像MATLAB

[英]overlaping binary image on the RGB image MATLAB

i am able to overlap the binary image with the original RGB image. 我能够将二进制图像与原始RGB图像重叠。 Through the following code. 通过以下代码。

inImage = imresize(imread('1.jpg'),0.25);
%imwrite(inImage,'original.jpg');
inImage = skyremoval(inImage);
greyImage = rgb2gray(inImage);


thresh1 = 200;
whiteLayer = greyImage > thresh1;


thresh2 = 125;
lightgreyLayer = greyImage > thresh2 & greyImage <= thresh1;



layer1 = whiteLayer*200;
layer2 = lightgreyLayer*125;


G = layer1 + layer2;
% figure,imshow(G);


se = strel('disk', 15);
Io = imopen(G, se);
figure,imshow(Io);

f = find(Io==0);

 mask(:,:,1) = f;  % For the red plane
%  mask(:,:,2) = f;  % For the green plane
%  mask(:,:,3) = f;  % For the blue plane

inImage(mask)=0;
I = inImage;
figure,imshow(I);

The following are the images. 以下是图像。 Here .The first is the binary image derived from the original, second is the original and the third is the result after overlaping both binary and rgb images, by the code given above. 在这里 。第一个是从原始图像派生的二进制图像,第二个是原始图像,第三个是通过上面给出的代码将二进制图像和rgb图像重叠后的结果。 As you can see the problem i am facing is that the part except road is cyan all i want is the part which is not road to be black. 如您所见,我面临的问题是道路以外的部分是青色,我想要的只是道路不是黑色的部分。 How can i do that? 我怎样才能做到这一点?

Please alter my code if you can help. 如果可以的话,请更改我的代码。 Thank you. 谢谢。

You don't need the find command, since you can index with a binary image. 您不需要find命令,因为您可以使用二进制图像进行索引。

Instead of 代替

f = find(Io==0);

 mask(:,:,1) = f;  % For the red plane
%  mask(:,:,2) = f;  % For the green plane
%  mask(:,:,3) = f;  % For the blue plane

inImage(mask)=0;
I = inImage;
figure,imshow(I);

you can write 你可以写

mask = repmat(Io==0,1,1,3); %# 1 wherever mask is false
I = inImage;
I(mask) = 0;
figure,imshow(I);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM