How can I color all objects as the same in an image where several objects have been extracted in the form of a label matrix?

조회 수: 2 (최근 30일)
I don't want the objects to be of different colors - I want them all the same shade of red (or white or blue). How can I achieve this?
  댓글 수: 1
Matt J
Matt J 2022년 1월 7일
It is advisable in the forum to post code as text, rather than as an embedded image. That way, contributors can more easily copy/paste it.

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2022년 1월 8일
You don't need bwlabel(), label2rgb(), or colormaps. You can simply use imoverlay:
grayImage = imread('rice.png'); % A gray scale image.
mask = bwareaopen(imbinarize(grayImage, 'adaptive'), 8); % A binary/logical image.
% Overlay the mask onto the original image.
rgbImage = imoverlay(grayImage, mask, 'r'); % Creates a new RGB image.
imshow(rgbImage)

추가 답변 (1개)

Matt J
Matt J 2022년 1월 7일
편집: Matt J 2022년 1월 7일
Bianrize the labels,
RGB_label-label2rgb(labeled>0,___);
imshow(RGB_labels);
  댓글 수: 1
yanqi liu
yanqi liu 2022년 1월 8일
편집: yanqi liu 2022년 1월 8일
yes,sir,it is great mehod,may use code to check it
clc; clear all; close all;
im = imread('rice.png');
bw = bwareaopen(imbinarize(im, 'adaptive'), 8);
[labeled,num] = bwlabel(bw);
% make to one label
RGB_labels=label2rgb(labeled>0);
figure; imshow(RGB_labels);
% self define colorm map
cmap = ones(num, 3); cmap(:, 1:2) = 0; cmap(1,1) = 0;
RGB_labels2=label2rgb(labeled,cmap);
figure; imshow(RGB_labels2);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Blue에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by