FIND and rgb image

1 vue (au cours des 30 derniers jours)
nirit
nirit le 8 Déc 2017
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

Réponse acceptée

Image Analyst
Image Analyst le 8 Déc 2017
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);

Plus de réponses (0)

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by