How to color an image according to orientation of objects?

1 view (last 30 days)
I use the following code:
I = imread(picture);
BW = imbinarize(rgb2gray(I));
figure()
h = imshow(BW);
axis on
props = regionprops(BW, 'Orientation');
allAngles = [props.Orientation];
histogram(allAngles);
to get orientation histogram of all the objects on an image.
How can I get an image with orientations assigned for all the objects?
The following code seems not to work properly:
y= ismember(BW,find([props.Orientation]));
imagesc(BW+y )
title('Objects according to their orientations')
colormap()
As it shows only 2 colors, not the entire orientation spectrum.
I know it's probably like taking candy from a baby, but I'm a Matlab newbie.

Accepted Answer

Walter Roberson
Walter Roberson on 22 Feb 2020
When you regionprops(), also ask for PixelIdxList .
Now, create a matrix
orient = zeros(size(BW));
And loop through the struct array you got from regionprops:
orient(props(K).PixelIdxList) = props(K).orientation;
After this you can imshow() or imagesc() orient .
Note that very high orientations and very low orientations are close to each other, so you might want to use an hsv colormap or something similar that is "circular"
  4 Comments
Image Analyst
Image Analyst on 23 Feb 2020
How about you upload your picture so we can actually try it and see rather than guessing?

Sign in to comment.

More Answers (0)

Products


Release

R2015a

Community Treasure Hunt

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

Start Hunting!