Finding a way to measure the width and length automatically in image
5 views (last 30 days)
Show older comments
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
Answers (1)
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, []);
0 Comments
See Also
Categories
Find more on Image Segmentation and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!