Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
to find the area of hole

Subject: to find the area of hole

From: Nidhi

Date: 4 Sep, 2010 17:37:03

Message: 1 of 18

Hello sir,
I have an intensity image of pinhole and i want to calculate the area of that hole in the image. whatever i did till now is.... first i cropped my image in a square around that hole and after that i masked corners of square by fitting a circle inside the square. after that i count the number of pixels in the circular region but i m not aware of how to locate the proper edge of the hole so that i can make the difference between fitted circle and exact hole. I tried canny and almost all edge detectors for finding the edge but not getting satisfying results. please help me out to solve this problem with proper MATLAB code.



Regards
Nidhi
 

Subject: to find the area of hole

From: Image Analyst

Date: 4 Sep, 2010 17:57:03

Message: 2 of 18

Nidhi :
Try this image segmentation demo. Just pretend the coins in the image are holes. It automatically finds the coins and then measures their centroid, area, etc. Then try replacing the standard coin image with your own image.
-ImageAnalyst

Subject: to find the area of hole

From: Nidhi

Date: 4 Sep, 2010 18:23:05

Message: 3 of 18

"Image Analyst" <imageanalyst@mailinator.com> wrote in message <i5u19f$lnj$1@fred.mathworks.com>...
> Nidhi :
> Try this image segmentation demo. Just pretend the coins in the image are holes. It automatically finds the coins and then measures their centroid, area, etc. Then try replacing the standard coin image with your own image.
> -ImageAnalyst

Sir, I have already tried these kind of coins demo with the help of MATLAB Help section but the problem is i need to calculate area of the pinhole in terms of metric units and the thing is that its radius is known to me. I just need to compare my area using MATLAB code with the area calucated by the (pi*radius^2)formula for another software validation. The coins demo find out the area with some approximations which i really dont understand. please give me some MATLAB code for proper edge detection of hole or some way to count the subpixels in the circular area because i think pixels are of square shape and even if we count number of pixels in a circular region it is giving the pixels in whole number. How the whole number of pixels can fit into circular region i really dont understand.
Regards
Nidhi

Subject: to find the area of hole

From: ImageAnalyst

Date: 4 Sep, 2010 18:30:11

Message: 4 of 18

Simply multiply your ECD (equivalent circular diameter) by your
spatial calibration in mm/pixel and then you have it in mm. ALL image
processing software works in pixels. You have to supply the
calibration if you want it in real world units. For example, you need
to image a ruler or some other object of known length. Then you can
calculate how many pixel per mm or mm per pixel you have.

Subject: to find the area of hole

From: ImageAnalyst

Date: 4 Sep, 2010 18:56:41

Message: 5 of 18

Post your image to http://drop.io

All pixels are rectangular - there are no amorphously shaped pixels.
So ANY image of a circle will be in rectangular pixels. It doesn't
matter. You can always find the area in pixels, which may vary
slightly depending on what threshold you picked. Some pixels may be
not selected while others are completely selected, when what you want
is, say, half a pixel. But over the whole perimeter, it will on
average be correct. The ECD would most likely not change much if you
had pixels 100 times smaller, or round pixels or triangular pixels or
hexagonal pixels. That's why I say it doesn't matter, as long as you
have more than about 20 to 50 pixels in your circle. If you think I'm
wrong then post your low res image and your high res image and show me
that the ECD is substantially different between the two images. I
doubt you have some super precise measurement needed, like you are
designing some parts for the space station or something. This is
probably just some simple student project and you don't need to worry
that much about it.

Subject: to find the area of hole

From: Nidhi

Date: 4 Sep, 2010 19:03:03

Message: 6 of 18

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <fb4bc751-a9a2-472d-821b-23a52a720f94@t2g2000yqe.googlegroups.com>...
> Simply multiply your ECD (equivalent circular diameter) by your
> spatial calibration in mm/pixel and then you have it in mm. ALL image
> processing software works in pixels. You have to supply the
> calibration if you want it in real world units. For example, you need
> to image a ruler or some other object of known length. Then you can
> calculate how many pixel per mm or mm per pixel you have.

I know sir , to convert area in metric unit we need to have some calibrating object of known value. but if we have an image of known length ruler (bar of known length), then how will we calculate pixels per mm by this image, i mean can you please tell me MATALB code for calculating the pixels along that ruler( like a bar of known value in SEM(Scanning electron microscope) image of some nanosize object). I need MATLAB code to count number of pixels along a bar(known value) in an image of pinhole

Regards
Nidhi

Subject: to find the area of hole

From: ImageAnalyst

Date: 4 Sep, 2010 19:05:23

Message: 7 of 18

I have code for that on my other computer. I'll see if I can get it
later today.

Subject: to find the area of hole

From: Nidhi

Date: 4 Sep, 2010 19:27:03

Message: 8 of 18

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <7063b37c-d27e-4066-b2dc-41d12be58aa8@y11g2000yqm.googlegroups.com>...
> I have code for that on my other computer. I'll see if I can get it
> later today.

Thank you in advance sir. I will wait for the code.

Subject: to find the area of hole

From: Nidhi

Date: 4 Sep, 2010 19:49:04

Message: 9 of 18

"Nidhi " <nidhi.iitd@ymail.com> wrote in message <i5u6i7$pnl$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <7063b37c-d27e-4066-b2dc-41d12be58aa8@y11g2000yqm.googlegroups.com>...
> > I have code for that on my other computer. I'll see if I can get it
> > later today.
>
> Thank you in advance sir. I will wait for the code.


Thank you sir for devoting time to solve my problem. I have posted my image kindly have a look and suggest me the steps needed according to you for calculation of area of hole and please tell the MATLAB code.

Regards
Nidhi

Subject: to find the area of hole

From: Image Analyst

Date: 4 Sep, 2010 21:30:08

Message: 10 of 18

"Nidhi " <nidhi.iitd@ymail.com> wrote in message

I have posted my image ....
---------------------------------------------------
And where did you post it? What's the URL?

Subject: to find the area of hole

From: ImageAnalyst

Date: 4 Sep, 2010 21:40:48

Message: 11 of 18

On Sep 4, 5:30 pm, "Image Analyst" <imageanal...@mailinator.com>
wrote:
> "Nidhi " <nidhi.i...@ymail.com> wrote in message
>
> I have posted my image ....
> ---------------------------------------------------
> And where did you post it?  What's the URL?

Here's some code to have the user draw a known distance. The
calibration can optionally be saved in a file for later recall, if
desired. It's pretty well commented so I'm sure you'll be able to
adapt it as needed.

% --- Executes on button press in btnCalib.
function btnCalib_Callback(hObject, eventdata, handles)
% hObject handle to btnCalib (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global lastDrawnHandle;
global calibration;

instructions = sprintf('Left click to anchor first endpoint of line.
\nRight-click or double-left-click to anchor second endpoint of line.\n
\nAfter that I will ask for the real-world distance of the line.');
set(handles.txtInfo, 'string', instructions);
msgboxw(instructions);

axes(handles.axesImage);
[cx,cy, rgbValues, xi,yi] = improfile(1000);
% rgbValues is 1000x1x3. Call Squeeze to get rid of the singleton
dimension and make it 1000x3.
rgbValues = squeeze(rgbValues);
distanceInPixels = sqrt( (xi(2)-xi(1)).^2 + (yi(2)-yi(1)).^2);
if length(xi) < 2 then
return;
end
% Plot the line.
hold on;
lastDrawnHandle = plot(xi, yi, 'y-', 'LineWidth', 2);

% Ask the user for the real-world distance.
userPrompt = {'Enter real world units (e.g. microns):','Enter
distance in those units:'};
dialogTitle = 'Specify calibration information';
numberOfLines = 1;
def = {'microns', '500'};
answer = inputdlg(userPrompt, dialogTitle, numberOfLines, def);
calibration.units = answer{1};
calibration.distanceInPixels = distanceInPixels;
calibration.distanceInUnits = str2double(answer{2});
calibration.distancePerPixel = calibration.distanceInUnits /
distanceInPixels;

reply = questdlg({'Do you want to save the calibration', 'to disk for
later use?'},'Save calibration?', 'Yes','No', 'Yes');
% reply = '' for Upper right X, 'Yes' for Yes, 'No' for No.
%uiwait();
if strcmp(reply, 'Yes')
[fileName, folder] = uiputfile([handles.CalibrationFolder '/
Calibration.mat'], 'Save file name');
[folder, baseFileName, ext, version] = fileparts(fileName);
calibrationFileName = fullfile(handles.CalibrationFolder,
[baseFileName '.mat']);
% Save the calibration for later recall if desired.
save(calibrationFileName, 'calibration');
% Refresh the listbox of calibrations.
handles = LoadCalibrationList(handles);
end
return; % from btnCalib_Callback()

Subject: to find the area of hole

From: Nidhi

Date: 5 Sep, 2010 08:31:06

Message: 12 of 18

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <1d163a6a-c595-4210-a551-696447a49bbc@s9g2000yqd.googlegroups.com>...
> On Sep 4, 5:30 pm, "Image Analyst" <imageanal...@mailinator.com>
> wrote:
> > "Nidhi " <nidhi.i...@ymail.com> wrote in message
> >
> > I have posted my image ....
> > ---------------------------------------------------
> > And where did you post it?  What's the URL?
>
> Here's some code to have the user draw a known distance. The
> calibration can optionally be saved in a file for later recall, if
> desired. It's pretty well commented so I'm sure you'll be able to
> adapt it as needed.
>
> % --- Executes on button press in btnCalib.
> function btnCalib_Callback(hObject, eventdata, handles)
> % hObject handle to btnCalib (see GCBO)
> % eventdata reserved - to be defined in a future version of MATLAB
> % handles structure with handles and user data (see GUIDATA)
> global lastDrawnHandle;
> global calibration;
>
> instructions = sprintf('Left click to anchor first endpoint of line.
> \nRight-click or double-left-click to anchor second endpoint of line.\n
> \nAfter that I will ask for the real-world distance of the line.');
> set(handles.txtInfo, 'string', instructions);
> msgboxw(instructions);
>
> axes(handles.axesImage);
> [cx,cy, rgbValues, xi,yi] = improfile(1000);
> % rgbValues is 1000x1x3. Call Squeeze to get rid of the singleton
> dimension and make it 1000x3.
> rgbValues = squeeze(rgbValues);
> distanceInPixels = sqrt( (xi(2)-xi(1)).^2 + (yi(2)-yi(1)).^2);
> if length(xi) < 2 then
> return;
> end
> % Plot the line.
> hold on;
> lastDrawnHandle = plot(xi, yi, 'y-', 'LineWidth', 2);
>
> % Ask the user for the real-world distance.
> userPrompt = {'Enter real world units (e.g. microns):','Enter
> distance in those units:'};
> dialogTitle = 'Specify calibration information';
> numberOfLines = 1;
> def = {'microns', '500'};
> answer = inputdlg(userPrompt, dialogTitle, numberOfLines, def);
> calibration.units = answer{1};
> calibration.distanceInPixels = distanceInPixels;
> calibration.distanceInUnits = str2double(answer{2});
> calibration.distancePerPixel = calibration.distanceInUnits /
> distanceInPixels;
>
> reply = questdlg({'Do you want to save the calibration', 'to disk for
> later use?'},'Save calibration?', 'Yes','No', 'Yes');
> % reply = '' for Upper right X, 'Yes' for Yes, 'No' for No.
> %uiwait();
> if strcmp(reply, 'Yes')
> [fileName, folder] = uiputfile([handles.CalibrationFolder '/
> Calibration.mat'], 'Save file name');
> [folder, baseFileName, ext, version] = fileparts(fileName);
> calibrationFileName = fullfile(handles.CalibrationFolder,
> [baseFileName '.mat']);
> % Save the calibration for later recall if desired.
> save(calibrationFileName, 'calibration');
> % Refresh the listbox of calibrations.
> handles = LoadCalibrationList(handles);
> end
> return; % from btnCalib_Callback()



Sir i have posted my image via e-mail to http://drop.io after which i got Admin Password: rgypa96a62 on my mail Id. The MATALB code that you have posted is quite lengthy although it is well commented still being a MATLAB learner it seems quite complicated. Would you please like to tell me in simple language that what are the basic steps ,you followed in the given code and how can I use it for my image. I was trying to run this code but in the very first line it is showing the error: Error: Function definitions are not permitted at the prompt or in scripts. Kindly suggest me what to do for it.

Subject: to find the area of hole

From: Nidhi

Date: 5 Sep, 2010 08:44:07

Message: 13 of 18

"Nidhi " <nidhi.iitd@ymail.com> wrote in message <i5vkga$39c$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <1d163a6a-c595-4210-a551-696447a49bbc@s9g2000yqd.googlegroups.com>...
> > On Sep 4, 5:30 pm, "Image Analyst" <imageanal...@mailinator.com>
> > wrote:
> > > "Nidhi " <nidhi.i...@ymail.com> wrote in message
> > >
> > > I have posted my image ....
> > > ---------------------------------------------------
> > > And where did you post it?  What's the URL?
> >
> > Here's some code to have the user draw a known distance. The
> > calibration can optionally be saved in a file for later recall, if
> > desired. It's pretty well commented so I'm sure you'll be able to
> > adapt it as needed.
> >
> > % --- Executes on button press in btnCalib.
> > function btnCalib_Callback(hObject, eventdata, handles)
> > % hObject handle to btnCalib (see GCBO)
> > % eventdata reserved - to be defined in a future version of MATLAB
> > % handles structure with handles and user data (see GUIDATA)
> > global lastDrawnHandle;
> > global calibration;
> >
> > instructions = sprintf('Left click to anchor first endpoint of line.
> > \nRight-click or double-left-click to anchor second endpoint of line.\n
> > \nAfter that I will ask for the real-world distance of the line.');
> > set(handles.txtInfo, 'string', instructions);
> > msgboxw(instructions);
> >
> > axes(handles.axesImage);
> > [cx,cy, rgbValues, xi,yi] = improfile(1000);
> > % rgbValues is 1000x1x3. Call Squeeze to get rid of the singleton
> > dimension and make it 1000x3.
> > rgbValues = squeeze(rgbValues);
> > distanceInPixels = sqrt( (xi(2)-xi(1)).^2 + (yi(2)-yi(1)).^2);
> > if length(xi) < 2 then
> > return;
> > end
> > % Plot the line.
> > hold on;
> > lastDrawnHandle = plot(xi, yi, 'y-', 'LineWidth', 2);
> >
> > % Ask the user for the real-world distance.
> > userPrompt = {'Enter real world units (e.g. microns):','Enter
> > distance in those units:'};
> > dialogTitle = 'Specify calibration information';
> > numberOfLines = 1;
> > def = {'microns', '500'};
> > answer = inputdlg(userPrompt, dialogTitle, numberOfLines, def);
> > calibration.units = answer{1};
> > calibration.distanceInPixels = distanceInPixels;
> > calibration.distanceInUnits = str2double(answer{2});
> > calibration.distancePerPixel = calibration.distanceInUnits /
> > distanceInPixels;
> >
> > reply = questdlg({'Do you want to save the calibration', 'to disk for
> > later use?'},'Save calibration?', 'Yes','No', 'Yes');
> > % reply = '' for Upper right X, 'Yes' for Yes, 'No' for No.
> > %uiwait();
> > if strcmp(reply, 'Yes')
> > [fileName, folder] = uiputfile([handles.CalibrationFolder '/
> > Calibration.mat'], 'Save file name');
> > [folder, baseFileName, ext, version] = fileparts(fileName);
> > calibrationFileName = fullfile(handles.CalibrationFolder,
> > [baseFileName '.mat']);
> > % Save the calibration for later recall if desired.
> > save(calibrationFileName, 'calibration');
> > % Refresh the listbox of calibrations.
> > handles = LoadCalibrationList(handles);
> > end
> > return; % from btnCalib_Callback()
>
>
>
> Sir i have posted my image via e-mail to http://drop.io after which i got Admin Password: rgypa96a62 on my mail Id. The MATALB code that you have posted is quite lengthy although it is well commented still being a MATLAB learner it seems quite complicated. Would you please like to tell me in simple language that what are the basic steps ,you followed in the given code and how can I use it for my image. I was trying to run this code but in the very first line it is showing the error: Error: Function definitions are not permitted at the prompt or in scripts. Kindly suggest me what to do for it. Sorry i have posted my image via email to mvzd4cs@drop.io after which i got Admin Password: rgypa96a62 on my mail Id.

Subject: to find the area of hole

From: ImageAnalyst

Date: 5 Sep, 2010 14:06:05

Message: 14 of 18

On Sep 5, 4:31 am, "Nidhi " <nidhi.i...@ymail.com> wrote:
> Sir i have posted my image via e-mail tohttp://drop.ioafter which i got Admin Password: rgypa96a62 on my mail Id. The MATALB code that you have posted is quite lengthy although it is well commented still being a MATLAB learner it seems quite complicated. Would you please like to tell me in simple language that what are the basic steps ,you followed in the given code and how can I use it for my image. I was trying to run this code but in the very first line it is showing the error: Error: Function definitions are not permitted at the prompt or in scripts. Kindly suggest me what to do for it.
----------------------------------------------------------------------------------------------

You still haven't give the URL. You gave the password to your drop,
but you didn't give the URL of the drop itself. Plus, why force a
password? You don't need one and it just puts another roadblock in my
way.

A bright college student like you should be able to follow along with
the code. But if you really need to point out the essential, basic,
key statements of the thing, it's these:

[cx,cy, rgbValues, xi,yi] = improfile(1000);
distanceInPixels = sqrt( (xi(2)-xi(1)).^2 + (yi(2)-yi(1)).^2);

What this does is ask the user to draw a polyline, then it calculates,
via the Pythagorean theorem, the distance between the two endpoints.
Then you ask the user for the real world distance and calculate the
ratio

distancePerPixel = distanceInUnits / distanceInPixels;

That is your spatial calibration factor. Then for any given pixel
distance, say xd, you simply multiply xd by distancePerPixel to get
the distance in your real world units.

That's basically it. If you want to code that up yourself in code you
can understand, go ahead.
-ImageAnalyst

Subject: to find the area of hole

From: Nidhi

Date: 6 Sep, 2010 09:13:06

Message: 15 of 18

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <dfc9d51a-7068-413e-a959-986ea55a61a1@u6g2000yqh.googlegroups.com>...
> On Sep 5, 4:31 am, "Nidhi " <nidhi.i...@ymail.com> wrote:
> > Sir i have posted my image via e-mail tohttp://drop.ioafter which i got Admin Password: rgypa96a62 on my mail Id. The MATALB code that you have posted is quite lengthy although it is well commented still being a MATLAB learner it seems quite complicated. Would you please like to tell me in simple language that what are the basic steps ,you followed in the given code and how can I use it for my image. I was trying to run this code but in the very first line it is showing the error: Error: Function definitions are not permitted at the prompt or in scripts. Kindly suggest me what to do for it.
> ----------------------------------------------------------------------------------------------
>
> You still haven't give the URL. You gave the password to your drop,
> but you didn't give the URL of the drop itself. Plus, why force a
> password? You don't need one and it just puts another roadblock in my
> way.
>
> A bright college student like you should be able to follow along with
> the code. But if you really need to point out the essential, basic,
> key statements of the thing, it's these:
>
> [cx,cy, rgbValues, xi,yi] = improfile(1000);
> distanceInPixels = sqrt( (xi(2)-xi(1)).^2 + (yi(2)-yi(1)).^2);
>
> What this does is ask the user to draw a polyline, then it calculates,
> via the Pythagorean theorem, the distance between the two endpoints.
> Then you ask the user for the real world distance and calculate the
> ratio
>
> distancePerPixel = distanceInUnits / distanceInPixels;
>
> That is your spatial calibration factor. Then for any given pixel
> distance, say xd, you simply multiply xd by distancePerPixel to get
> the distance in your real world units.
>
> That's basically it. If you want to code that up yourself in code you

 can understand, go ahead.
> -ImageAnalyst

Sorry sir but can you please tell me where i have to post my image so that i might be able to do spatial calibration. I have not worked on MATLAB GUI. It is very new for me and thats why i m having problem to understand like the kind of function( Callback, hObject, handles and all these sort of words) u have used in the above code. It might be silly question for you but any help regarding this would be highly appreciated.

Subject: to find the area of hole

From: ImageAnalyst

Date: 6 Sep, 2010 13:04:02

Message: 16 of 18

Go to http://drop.io. It will ask you to create a URL. In the field,
type in your name so that now, the URL it will create will be
http://drop.io/nidhi. Then browse to your file to upload it, and then
tell us what URL you created, for example http://drop.io/nidhi.

You might find it easier to use GUIDE to create GUIs. It's a visual
way of adding controls to the GUI and setting properties. I find it
much easier than doing it the manual way with the uicontrol() function
in my code.

Subject: to find the area of hole

From: Nidhi

Date: 7 Sep, 2010 07:44:05

Message: 17 of 18

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <af11b30e-8717-4ca9-964d-9ceea9555709@v41g2000yqv.googlegroups.com>...
> Go to http://drop.io. It will ask you to create a URL. In the field,
> type in your name so that now, the URL it will create will be
> http://drop.io/nidhi. Then browse to your file to upload it, and then
> tell us what URL you created, for example http://drop.io/nidhi.
>
> You might find it easier to use GUIDE to create GUIs. It's a visual
> way of adding controls to the GUI and setting properties. I find it
> much easier than doing it the manual way with the uicontrol() function
> in my code.

Thank you sir for your support. I have posted my image n URL is http://drop.io/nidhi_iit
Please find it, there are two image files one is sem1.tiff and other is pin85.jpg in which sem1.tiff file there is a sem bar for calibration and other image is of pinhole(my original problem to find out the area of pinhole). Please have a look and make me suggest, what can I do for calibration and area calculation in metric units. Please tell me how calibration can be done by using the code given by you.

Regards
Nidhi

Subject: to find the area of hole

From: Nidhi

Date: 9 Sep, 2010 10:04:04

Message: 18 of 18

"Nidhi " <nidhi.iitd@ymail.com> wrote in message <i64qg5$mhl$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <af11b30e-8717-4ca9-964d-9ceea9555709@v41g2000yqv.googlegroups.com>...
> > Go to http://drop.io. It will ask you to create a URL. In the field,
> > type in your name so that now, the URL it will create will be
> > http://drop.io/nidhi. Then browse to your file to upload it, and then
> > tell us what URL you created, for example http://drop.io/nidhi.
> >
> > You might find it easier to use GUIDE to create GUIs. It's a visual
> > way of adding controls to the GUI and setting properties. I find it
> > much easier than doing it the manual way with the uicontrol() function
> > in my code.
>
> Thank you sir for your support. I have posted my image n URL is http://drop.io/nidhi_iit
> Please find it, there are two image files one is sem1.tiff and other is pin85.jpg in which sem1.tiff file there is a sem bar for calibration and other image is of pinhole(my original problem to find out the area of pinhole). Please have a look and make me suggest, what can I do for calibration and area calculation in metric units. Please tell me how calibration can be done by using the code given by you.
>
> Regards
> Nidhi

Please help me to solve this problem. I have posted you my image on the URL http://drop.io/nidhi_iit

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us