Marking images in different colors

I use the labeling algorithm for connected components in Matlab. Can I use different colors for different labels when displaying output? (Although the tags have the same intensity).

Clarification:
I used the tagging algorithm for connected components to identify connected binary image components. Now I have different labels. All labels contain a pixel of equal intensity. (All labels have a pixel intensity value of 1), and all labels are displayed in the same color. I want to display different labels using different colors so that I can more easily get rid of unwanted ones.

+4
source share
1 answer

It's easy - use the imagesc function:

 p = imread('peppers.png'); %Read image b = (p(:,:,2)>100); % Thresholding by some constant threshold 

If you already have a binary image, just use this section of code: ( b is the image)

 L = bwlabel(b); %Find components figure(); %Create figure imagesc(L); %Draw the components, each in its own color. 

enter image description here

You can also change colors using the colormap :

  colormap(bone) 

enter image description here

To customize the colors, define an nx3 matrix and pass it as input to colormap

 cm = [1 0 0; 0 1 0; 0 0 1 0 1 1 1 1 0 ]; colormap(cm) 
+3
source

Source: https://habr.com/ru/post/1393812/


All Articles