Color Label Image By Region Property

9 views (last 30 days)
Nicholas Sbalbi
Nicholas Sbalbi on 15 Sep 2023
Answered: Image Analyst on 16 Sep 2023
I have a binarized image with multiple identified regions that each have a particular orientation. I would like to color the identified regions (similar to label2rgb) where the color is related to a given region's property (in this case orientation). For example, I'd want the orientation to map from (-90, 90) onto a HSV colormap. Is there a way to do this?

Answers (2)

Walter Roberson
Walter Roberson on 15 Sep 2023
discretize the orientation angle into an integer, uint8() that, then ind2rgb

Image Analyst
Image Analyst on 16 Sep 2023
You can still use label2rgb -- just construct your colormap so that each row has the color you want for that particular blob (based on it's orientation)
help label2rgb
LABEL2RGB Convert label matrix to RGB image. RGB = LABEL2RGB(L) converts a label or a categorical matrix L, into a color RGB image for the purpose of visualizing the labeled regions. RGB = LABEL2RGB(L, MAP) defines the colormap to be used in the RGB image. MAP can either be an n x 3 colormap matrix, a string or a character vector containing the name of a colormap function (such as 'jet' or 'gray'), or a function handle of a colormap function (such as @jet or @gray). LABEL2RGB evaluates MAP so that there is a different color for each region in L. If MAP is not specified, 'jet' is used as the default. RGB = LABEL2RGB(L, MAP, ZEROCOLOR) defines the RGB color of the elements labeled 0 or <undefined> in the input label matrix L. ZEROCOLOR can either be an RGB triple, or one of the following: 'y' (yellow), 'm', (magenta), 'c' (cyan), 'r'(red), 'g' (green), 'b' (blue), 'w' (white), or 'k' (black). If ZEROCOLOR is not specified, [1 1 1] is used as the default. RGB = LABEL2RGB(L, MAP, ZEROCOLOR, ORDER), controls how colormap colors are assigned to regions in the label matrix. If ORDER is 'noshuffle' (the default), then colormap colors are assigned to the label matrix regions in numerical order. If ORDER is 'shuffle', then colormap colors are pseudorandomly shuffled. RGB = LABEL2RGB(...,Name,Value) specifies additional name-value pair arguments described below: 'OutputFormat' Specify the output format. Valid values are: 'image' The output is an M-by-N-by-3 image where M-by-N is the size of the input label matrix. 'triplets' The output is an M-by-3 matrix where each row is an 1-by-3 RGB triplet and M is the number of elements in the input label matrix. Specify this value when you want to convert a list of labels into a list of RGB colors. Default: 'image' Class Support ------------- The input label matrix L can be numeric or categorical. When L is numeric, it must contain finite nonnegative integers. RGB is uint8. Example 1 --------- %Use label2rgb to customize display of label matrix. I = imread('rice.png'); figure, imshow(I) BW = imbinarize(I); CC = bwconncomp(BW); L = labelmatrix(CC); RGB = label2rgb(L); RGB2 = label2rgb(L, 'spring', 'c', 'shuffle'); figure, imshow(RGB), figure, imshow(RGB2) Example 2 --------- %Use label2rgb to display categorical label matrix. load('buildingPixelLabeled','label'); RGB = label2rgb(label); figure, imshow(RGB) See also BWCONNCOMP,BWLABEL,COLORMAP,ISMEMBER,LABELMATRIX,WATERSHED. Documentation for label2rgb doc label2rgb

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!