Measure the length of the spiral object in the photo

5 views (last 30 days)
Hi,
how can i measure the length of the spiral loop with image processing? The following is my input image.
  3 Comments
Pratheek Ullal
Pratheek Ullal on 27 Feb 2019
The length is measured in mm along the inner or outer edge of each loop. the image shows the reference scale to measure the spiral loop.911B717D-E218-4A4E-B5BF-A92015150E6A.jpeg
Pratheek Ullal
Pratheek Ullal on 27 Feb 2019
Lenghth is measured in mm along the inner or outer edge of each loop in the spiral coil.

Sign in to comment.

Answers (1)

Arnav
Arnav ungefär 15 timmar ago
To measure the length of the black spiral object, you may use the following image processing pipeline in MATLAB:
The steps can be summarized as:
  • Convert to grayscale: Since the image is a dark object against a bright background, we can convert it to grayscale without any meaningful loss of data. This is done using rgb2gray function.
  • Increase the contrast of the image: This is done to saturate the lower and higher 10% of intensity. This is done using imadjust function.
  • Binarize and negate the image: This step converts the adjusted grayscale image into a binary image using adaptive thresholding. The image is then negated to ensure the object of interest is white against a black background.
  • Remove smaller components: Small noise and irrelevant components are removed from the binary image using the bwareaopen function, which retains only the components larger than a specified size.
  • Morphological closing: This operation is performed to close small gaps in the binary image, using a disk-shaped structuring element. It helps in connecting disjointed parts of the object.
  • Skeletonization: The binary image is reduced to a skeletal form using the bwskel function, which preserves the topology of the object while reducing it to a single-pixel-wide representation.
This can be done in MATLAB using the following code snippet:
% Read the image from the specified path
image = imread('path\to\image.jpeg');
% Convert the image to grayscale
grayImage = rgb2gray(image);
% Increase the contrast of the grayscale image
adjustedGrayImage = imadjust(grayImage);
% Binarize the image using adaptive thresholding and negate it
bwImage = imbinarize(adjustedGrayImage, 'adaptive', 'ForegroundPolarity', 'dark', 'Sensitivity', 0.4);
bwImage = ~bwImage;
% Remove small objects from the binary image
bwImage = bwareaopen(bwImage, 100);
% Perform morphological closing to fill small gaps
bwImage = imclose(bwImage, strel('disk', 5));
% Skeletonize the binary image
skeleton = bwskel(bwImage);
% Prune the skeleton to remove small spurs
prunedSkeleton = bwmorph(skeleton, 'spur', 20);
% Label the connected components in the pruned skeleton
[labeledSkeleton, num] = bwlabel(prunedSkeleton);
% Measure the area of each component
componentLengths = regionprops(labeledSkeleton, 'Area');
% Find the largest component based on area
[~, largestIdx] = max([componentLengths.Area]);
% Extract the largest skeleton component
largestSkeleton = ismember(labeledSkeleton, largestIdx);
You can learn more about the functions used here:
The identified arc of the spiral is shown below:
Then, the length of the spiral can be estimated as:
length = scale*sum(largestSkeleton(:))
It should be noted that the length of the spiral may not exactly match the real data as there may be imperfections/artefacts in the image. You may fine-tune this by adjusting the parameters in the pipeline.
See if it helps you.

Community Treasure Hunt

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

Start Hunting!