How to get depth information from surface image

2 Ansichten (letzte 30 Tage)
Bhavin  Sohaliya
Bhavin Sohaliya am 21 Jul. 2017
Kommentiert: Image Analyst am 7 Mai 2024
I have written the following matlab code to do the following:-
  • load rgb image of surface
  • contrast stretch
  • convert rgb to gray scale
  • convert gray to binary image
  • select appropriate portion of the image
  • fill hole in the binary image
  • find and plot the centroid of image
  • estimate radius of circular part and plot circle
My aim is to develop the SIMPLEST matlab code for automatic detection of indentation and calculate the diameter and depth of the indentation (if possible other geometrical properties) from a sample image.
The code is shown below:
% read the image from file
rgbImage = imread('V1.nn.bmp');
subplot(2,3,1);
imshow(rgbImage,[]);
axis on;
title('original image');
% Image adjust
Istretch = imadjust(rgbImage,stretchlim(rgbImage));
subplot(2,3,2);
imshow(Istretch,[])
axis on;
title('Contrast stretched image')
% convert the original image into gray image
gry = rgb2gray(Istretch);
subplot(2,3,3);
imshow(gry,[]);
axis on;
title('original gray image');
% convert gray image to binary image
level = graythresh(Istretch);
binaryImage = im2bw(gry,level);
subplot(2,3,4);
imshow(binaryImage);
title('binary masked image');
% select appropriate portion of the image
areafilt = bwareafilt(binaryImage, 1, 'largest');
subplot(2,3,5);
imshow(areafilt);
title('main part of the image');
% fill hole in the binary image
fillHole=imfill(areafilt,'holes');
subplot(2,3,6);
imshow(fillHole);
title('filled hole of the image');
%%find and plot the centroid of image
stats = regionprops('table',fillHole,'Centroid','Area',...
'MajorAxisLength','MinorAxisLength','EquivDiameter')
figure;
imshow(fillHole);
centroids=cat(1,stats.Centroid);
areas=cat(1,stats.Area);
hold on;
plot(centroids(:,1), centroids(:,2), 'r*','MarkerSize', 10, 'LineWidth', 1);
hold off;
% estimate radius of circular part and plot circle
diameter = mean([stats.MajorAxisLength stats.MinorAxisLength],2)
radii = diameter/2
hold on
viscircles(centroids,radii);
hold off
title('circle with centroid of the image');
I = surf(gry);
I tried surf function for depth information and it seems to get messy. I need help from image specialist to improve the code from above to meet my aim. The image V1.nn.bmp is attached, please find it.
Thank you.
  4 Kommentare
Shomya
Shomya am 7 Mai 2024
Then how to convert it to centimeter?
Image Analyst
Image Analyst am 7 Mai 2024
@Shomya You have to know how many cm are in a pixel. For example if your field of view is 10 cm and it's 1980 pixels wide
cmPerPixel = 10/1980;
distanceInCm = distanceInPixels * cmPerPixel;
See attached demo on spatial calibration.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 21 Jul. 2017
Mozilla/Firefox has banned that web site saying it's been improperly configured, so we can't see it, unless someone is running an old browser. Basically the original image should have depth information in it, times a scale factor. You need to know what that scale factor is, like 0 gray levels is 10 cm, and 255 gray levels is 124 cm or whatever. Then you can create a look up table where any graylevel can be translated into a depth. But certainly don't do a contrast stretch - that will just destroy your depth calibration.
  1 Kommentar
Bhavin  Sohaliya
Bhavin Sohaliya am 18 Okt. 2017
Thank you so much for your suggestion. But I don't know that fixed scale factor and I have to evaluate too many sample images in which the image has large data in it. It is possible to evaluate depth information with the microscope manually, but it takes little bit longer time and I want to evaluate quickly with Matlab code. I also called improfile function in a grayscale image, but I did not get right values. I have attached the microscopic image, please kindly find it.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Geometric Transformation and Image Registration finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by