## how to convert color of a pixel gray to red

on 19 Mar 2019
Latest activity Commented on by Walter Roberson

### Walter Roberson (view profile)

on 23 Mar 2019
rgb2gray(g);
imshow(g);
how to convert color of a pixel gray to red plzz

Geoff Hayes

### Geoff Hayes (view profile)

on 19 Mar 2019
abdel - don't you need to assign an output to rgb2gray like
grayscaleImage = rgb2gray(g);
imshow(grayscaleImage);
As for converting a pixel gray to red...which pixel? what are the dimensions of grayscaleImage?

on 21 Mar 2019
for any pixel

### Walter Roberson (view profile)

on 21 Mar 2019
Edited by Walter Roberson

### Walter Roberson (view profile)

on 23 Mar 2019

rgbimage = im2double( repmat(grayscaleImage, 1, 1, 3) );
rgbimage(some_row, some_column, 1) = 1; %R
rgbimage(some_row, some_column, 2) = 0; %G
rgbimage(some_row, some_column, 3) = 0; %B
You can use the above with vectors of some_row and some_column as long as you want to change rectangular areas. If you have scattered row and column locations to set then
rgbimage = im2double( repmat(grayscaleImage, 1, 1, 3) );
[nrow, ncol, npane] = size(rgbimage);
idx = sub2ind([nrow, ncol], scattered_row, scattered_column);
rgbimage(idx + 0*nrow*ncol) = 1; %R
rgbimage(idx + 1*nrow*ncol) = 0; %G
rgbimage(idx + 2*nrow*ncol) = 0; %B

Show 1 older comment
Image Analyst

### Image Analyst (view profile)

on 23 Mar 2019
Then use some_column instead of some_colum, and try not using im2double() and set red channel to 255 instead of 1.
Walter Roberson

### Walter Roberson (view profile)

on 23 Mar 2019
The im2double and setting to 1 are there to avoid having to write code to figure out what the maximum value to write in should be, since we do not know cloass(grayscaleImage)
Walter Roberson

### Walter Roberson (view profile)

on 23 Mar 2019
My code works for me with camerman.tif . The one thing to note is that if you imshow(rgbimage) then the red pixels might be difficult to notice, especially if it is against a lighter background (red on dark is easier to notice.) You might want to draw your image larger if you are using imshow().