Clear Filters
Clear Filters

How to find out area under the curved shape of the attached figure?

1 view (last 30 days)

Accepted Answer

Image Analyst
Image Analyst on 16 Dec 2023
Try the attached code to automatically find the lower dark shape. It produces.
  5 Comments
Debasish Sarker
Debasish Sarker on 16 Dec 2023
I managed to solve the problems using help from your code, though threshold limit is manually selected. Thanks again!
Image Analyst
Image Analyst on 16 Dec 2023
If you have a variety of intensity levels, then that's not good. You should try to adjust your image capture parameters to get consistent exposure. If you can't do that then you'll have to come up with some algorithm to automatically threshold. Like maybe you can find the mean of the image, and then multiply by a factor so that the mean of a new image will be some known value, like 100. Then you could use the fixed threshold. Otherwise you'll have to do some tricky examination of the shape of the histogram and coms up with some way to find the threshold from that.
The imclearborder I used is available only in r2023b. If you can upgrade, do it. Otherwise you'll have to do some tricky operations with bwselect and imclearborder to remove the blob on the right, left, and top sides.
Doing medfilt2 before or after the thresholding is something I wondered about. Not sure which might be better. I just tried it on the grayscale image and it seemed to work fine, so I left it there. You can put it right after the initial mask creation and see if it's any better there.

Sign in to comment.

More Answers (1)

DGM
DGM on 15 Dec 2023
It's going to be up to you to define where the curve boundary is. It's not clear in concept or in terms of available contrast.
This can be done interactively, but for sake of demonstrating things on the forum, I'm going to have to do it programmatically.
% read the image
inpict = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1570032/image.jpeg');
inpict = im2gray(inpict);
% display the image
imshow(inpict);
% create the ROI interactively with the mouse
% i can't do this on the forum, obviously
%ROI = drawpolygon(gca);
% create the ROI programmatically for example
ROI = images.roi.Polygon(gca);
ROI.Position = [711.5 1600; 724.6 1428; 778.5 1206; 838.9 1035; ...
909.1 914; 1007 876.4; 1077 871.5; 1188 897.6; 1237 943.4; ...
1275 1014; 1329 1165; 1376 1394; 1387 1549; 1387 1600];
% create a mask from the image
mask = createMask(ROI);
% find the area in pixels
Apx = nnz(mask)
Apx = 389833
% find the area in mm
% you'll need some appropriate conversion factor
k = 0.1; % mm per px
Amm = Apx*k^2
Amm = 3.8983e+03

Community Treasure Hunt

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

Start Hunting!