Finding a way to measure the width and length automatically in image

9 views (last 30 days)
Hello, everyone. I want to ask a question about- how to measure my target's length (red) and width(orange) in an image automatically. My image will look like a point image and sometimes will have some noise point too. Do I need to convert it into a scatter plot before I do any fitting?
I am a super beginner at using Matlab, so please answer me as easily as possible. Thank you so much for helping me out during these difficult times. Your help will be invaluable!!!
  2 Comments
christine QQ
christine QQ on 3 Nov 2021
Yes, the true situation is non-constant along the length of the shape. So I am wondering is it possible to do so? I saw some people say that it can use curve fitting to find the length first. Then, use the centerline to find the width. Though, I still feel confused about how to convert my image into a plot, so that I can use curve fitting to find the length. Is it possible to convert my point image into a point plot?
Thank you for answering my question!!

Sign in to comment.

Answers (1)

yanqi liu
yanqi liu on 5 Nov 2021
clc; clear all; close all;
im = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/788865/image.png');
bw = im2bw(im);
bw = ~bw;
jm = im(:, round(size(bw,2)/2):end, :);
bw = bw(:, round(size(bw,2)/2):end);
bw2 = imclose(bw, strel('disk', 12));
bw2 = bwareafilt(bw2,1);
bw = logical(bw .* bw2);
bw = imclose(bw, strel('disk', 9));
bw = imopen(bw, strel('disk', 2));
be = bwmorph(bw, 'thin', inf);
be = imdilate(bwareafilt(be,1), strel('disk', 3));
jm1 = jm(:,:,1);jm2 = jm(:,:,2);jm3 = jm(:,:,3);
jm1(be)=255;jm2(be)=0;jm3(be)=0;
jm = cat(3,jm1,jm2,jm3);
figure; imshow(bw, []);
figure; imshow(be, []);
figure; imshow(jm, []);

Community Treasure Hunt

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

Start Hunting!