Coloring a river on a grayscale image
Afficher commentaires plus anciens
I'm currently trying to paint part of my image (a river) yellow but the end result is not only the river being yellow but a large yellow square right next to the image. Orginally the image is in grayscale so I've used cat() to concatenate my grayscale image (and apparently "turn" it into an RGB image?) but I'm still not sure what is actually going wrong.
originalIM_River = imread('fig_lista4_2.bmp');
figure,title('Original image'),imshow(originalIM_River)
imRGB_River = cat(3, originalIM_River, originalIM_River, originalIM_River);
[nLine, nColum] = size(originalIM_River); % Correct
%[nLine, nColumn] = size(imRGB_River); %Incorrect
for i = 1 : nLine
for j = 1 : nColumn
if imRGB_River(i,j) <= 48
imRGB_River(i,j,:) = [255,255,0]; % (255,255,0) is yellow
end
end
end
figure, title('New imagem - River painted with yellow'),imshow(imRGB_River)


I've tried to get each of the channels, and tried to change the colors of it to concatenate but still didn't work.
5 commentaires
David Goodmanson
le 22 Nov 2017
Hi Gabriel,
I killed off my answer because I had not checked it sufficiently
Gabriel Vilela
le 22 Nov 2017
What is
size(originalIM_River)
size(imRGB_River)
Does the problem still occur if you use
[nLine, nColumn, ~] = size(originalIM_River);
Gabriel Vilela
le 22 Nov 2017
Guillaume
le 22 Nov 2017
Yes, I suspected that nColumn was 3 times as big as you somehow were using a 2d syntax on a 3d matrix.
Note that using
[height, width, ~] = size(rgb_or_gray_image)
is guaranteed to work whether or not the image is grayscale or rgb.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Image Processing Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
