How to determine height of a particular color in an image?

2 views (last 30 days)
Alok Tiwari
Alok Tiwari on 29 Nov 2021
Edited: yanqi liu on 30 Nov 2021
Dear all,
I have series of images where i wanted to determine the height H.
First I converted it to hsv to obtain the following one -
After this what I can think of is:
Converting magenta color into matrix of pixel and identify distance between min and max value for each value. This way, I will have height at different columns, that I will average later to get average height (since, boundaries are not linear).
If somone can help me with the code or any lead, I will be thankful.

Answers (1)

yanqi liu
yanqi liu on 30 Nov 2021
Edited: yanqi liu on 30 Nov 2021
clc; clear all; close all;
img = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/817024/image.png');
jmg = rgb2ycbcr(img);
v = mat2gray(jmg(:,:,3));
bw = imbinarize(v,'adaptive');
bw2 = imclearborder(bw);
bw2 = bwareafilt(bw2, 1);
bw2 = imfill(bw2, 'holes');
stats = regionprops(bw2);
figure;
subplot(2,2,1); imshow(img);
hold on; rectangle('position', stats(1).BoundingBox, 'EdgeColor', 'g', 'LineWidth', 2)
subplot(2,2,2); imshow(v, []);
subplot(2,2,3); imshow(bw, []);
subplot(2,2,4); imshow(bw2, []);
fprintf('\nheight=%.1f\n',stats(1).BoundingBox(4));
height=110.0

Community Treasure Hunt

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

Start Hunting!

Translated by