FIND and rgb image

1 次查看(过去 30 天)
nirit
nirit 2017-12-8
I have rgb image (NxMx3) on which I want to mark some pixels in red. for that I have created a mask M (NxMx1), which values are all zeroes, except in the pixels I want to mark in red. I tried doing it using find, but it does not work like I wanted to and don't understand why.
for example, let say that
a=[1 2 3 4 5;6 7 8 9];
a=a./max(a(:));
img(:,:,1)=a;
img(:,:,2)=a;
img(:,:,3)=a;
M=[1 0 0 0;1 1 0 0 ];
[c,r]=find(M)
img(c,r,1)=1;
img(c,r,2)=0;
img(c,r,3)=0;
this give
img(:,:,1) =
1.0000 1.0000 0.3000 0.4000 0.5000
1.0000 1.0000 0.8000 0.9000 1.0000
img(:,:,2) =
0 0 0.3000 0.4000 0.5000
0 0 0.8000 0.9000 1.0000
img(:,:,3) =
0 0 0.3000 0.4000 0.5000
0 0 0.8000 0.9000 1.0000
instead of the wanted output, which is :
img(:,:,1) =
1 0.2000 0.3000 0.4000 0.5000
1 1 0.8000 0.9000 1.0000
img(:,:,2) =
0 0.2000 0.3000 0.4000 0.5000
0 0 0.8000 0.9000 1.0000
img(:,:,3) =
0 0.2000 0.3000 0.4000 0.5000
0 0 0.8000 0.9000 1.0000

采纳的回答

Image Analyst
Image Analyst 2017-12-8
Try this:
a=[1 2 3 4 5; 6 7 8 9 10];
a=a./max(a(:));
rgbImage(:,:,1)=a;
rgbImage(:,:,2)=a;
rgbImage(:,:,3)=a;
subplot(1, 3, 1);
imshow(rgbImage);
% Create mask
mask = logical([1 0 0 0 0;1 1 0 0 0]);
subplot(1, 3, 2);
imshow(mask);
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Apply mask to make it 1 in the red channel and 0 in the green and blue channels.
redChannel(mask) = 1;
greenChannel(mask) = 0;
blueChannel(mask) = 0;
% Recombine separate color channels into a single, true color RGB image.
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
subplot(1, 3, 3);
imshow(rgbImage);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by