Image processing for calculating length between two points on an image.

5 views (last 30 days)
Hello,
I am investigating a soltuion for calculating the width of cracks in lithium-ion batteries that have been damaged. I have CT scans of cross sections of the batteries, and I am looking to use MATLAB Image Processing Toolbox to calculate the width of the crack from these images.
So far, I have worked to isolate the battery casing from the image using some image processing functions, including segmenting the image with a global threshold and then retaining the object with the largest perimeter (the battery casing) using the bwpropfilt function. The code I have used for this is below.
I = imread('2D top view_310822_1238.jpg');
imshow(I)
title('Original CT Scan');
Igray = rgb2gray(I);
imshow(Igray)
Igray2 = imadjust(Igray);
imshow(Igray2)
BW = imbinarize(Igray2,"global");
imshow(BW)
BW2 = bwpropfilt(BW, 'perimeter', 1);
figure;
imshow(BW2)
I have also attached images of the original CT scan and the image BW2.
What I would now like to do is to calculate the point-to-point distance between the two ends of the battery casing. I have attached a third image, "Question_demonstration", to demonstrate this question.
Therefore, can somebody please suggest solutions to this problem?

Accepted Answer

Matt J
Matt J on 8 Feb 2024
Edited: Matt J on 8 Feb 2024
load BW2
[I,J]=find(bwmorph(bwskel(BW2),'endpoints'));
[~,k]=mink(J,2);
d=norm([ diff(I(k)), diff(J(k))])
d = 607.2833
  11 Comments
Matt J
Matt J on 9 Feb 2024
One of your example BW2s seems to be completely closed. Where are the endpoints needed to calculate d in this example,
imshow( load('300822_BW2.mat').BW2 )
Elliott Read
Elliott Read on 9 Feb 2024
Apologies, you're right. The original image seems not to have been binarized well. I have just generated another binary image using the color thresholder app that seems to generate a much better binary image. I have attached it here. Thanks.

Sign in to comment.

More Answers (0)

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!