How to change the background colour of this image to 0 and foreground colour to 1 to make it binary.
조회 수: 1 (최근 30일)
이전 댓글 표시
I tried this code but not working properly.
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Now make the mask
mask = ~(redChannel ~= 0 & greenChannel == 0 & blueChannel == 0);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226099/image.png)
댓글 수: 1
Guillaume
2019년 6월 24일
Your image looks like a labelised image to which false colours have been applied. Rather than trying to revert the false colouring, it would be better to work from the original labelised image. Don't you still have it?
답변 (2개)
Sulaymon Eshkabilov
2019년 6월 23일
Hi,
Here is a short code that reads and separates the three layers of colors:
AA = imread('Matrix.png');
R=AA(:,:,1);
G=AA(:,:,2);
B=AA(:,:,3);
imshow(AA)
RGB(:,:,1)=R;
RGB(:,:,2)=G;
RGB(:,:,3)=B;
imshow(RGB)
% Now you can change the values of any layer...
Good luck.
Image Analyst
2019년 6월 24일
You'd need
mask = ~(redChannel ~= 0 & greenChannel == 0 & blueChannel == 255);
% Mask the image using bsxfun() function to multiply the mask by each channel individually.
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, 'like', rgbImage));
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Display and Exploration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!