FIND and rgb image
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!