how to convert color of a pixel gray to red
조회 수: 9 (최근 30일)
이전 댓글 표시
g=imread('f8');
rgb2gray(g);
imshow(g);
how to convert color of a pixel gray to red plzz
댓글 수: 2
Geoff Hayes
2019년 3월 19일
abdel - don't you need to assign an output to rgb2gray like
g=imread('f8');
grayscaleImage = rgb2gray(g);
imshow(grayscaleImage);
As for converting a pixel gray to red...which pixel? what are the dimensions of grayscaleImage?
답변 (1개)
Walter Roberson
2019년 3월 21일
편집: Walter Roberson
2019년 3월 23일
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
댓글 수: 4
Walter Roberson
2019년 3월 23일
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
2019년 3월 23일
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().
참고 항목
카테고리
Help Center 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!