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:
Image Processing- Length of a line

Subject: Image Processing- Length of a line

From: Karthik NV

Date: 14 Nov, 2010 10:30:05

Message: 1 of 24

I want to find the real length of a line in an image. By this i mean the length that we perceive with our eyes and not the pixel length.
Here we are talking about complex shaped random lines that can be curves as well and these lines are anywhere from 2-6 pixels thick.
Can someone plzzzz help me on how to do this in matlab? Thanks a lot.

Subject: Image Processing- Length of a line

From: Walter Roberson

Date: 14 Nov, 2010 12:11:14

Message: 2 of 24

On 14/11/10 4:30 AM, Karthik NV wrote:
> I want to find the real length of a line in an image. By this i mean the
> length that we perceive with our eyes and not the pixel length.
> Here we are talking about complex shaped random lines that can be curves
> as well and these lines are anywhere from 2-6 pixels thick.
> Can someone plzzzz help me on how to do this in matlab? Thanks a lot.

I really don't think that humans perceive the length of complex curved
lines very well. To do so would require some fast sub-conscious elliptic
integrals (at the very least).

Do you perhaps mean something closer to "width of the bounding box" ?

Subject: Image Processing- Length of a line

From: Karthik NV

Date: 14 Nov, 2010 12:45:05

Message: 3 of 24

Walter Roberson <roberson@hushmail.com> wrote in message <ClQDo.470$2u4.77@newsfe03.iad>...
> On 14/11/10 4:30 AM, Karthik NV wrote:
> > I want to find the real length of a line in an image. By this i mean the
> > length that we perceive with our eyes and not the pixel length.
> > Here we are talking about complex shaped random lines that can be curves
> > as well and these lines are anywhere from 2-6 pixels thick.
> > Can someone plzzzz help me on how to do this in matlab? Thanks a lot.
>
> I really don't think that humans perceive the length of complex curved
> lines very well. To do so would require some fast sub-conscious elliptic
> integrals (at the very least).
>
> Do you perhaps mean something closer to "width of the bounding box" ?

Hi walter,
What i mean is for every figure you have a scale which tells us the real length of the line by comparison of what appears on the screen. If you take a thread and measure the length of the line on your computer screen and multiply it by the scale you must get the real length of the line!

I want to get close to this value by using imageprocessing tool box or by writing a matlab code. Can anyone help me with this please?

Subject: Image Processing- Length of a line

From: ImageAnalyst

Date: 14 Nov, 2010 13:42:05

Message: 4 of 24

Forget about the length of the line on your computer screen - that is
*totally* irrelevant. You DO want the pixel length of the line,
unlike what you first said. Then you need to multiply this by your
spatial calibration factor which is a number with units meters per
pixel, or whatever actual length units you want. Then you'll have
your answer. First of all you need to post your image somewhere so we
can see it. Otherwise how can we tell you how to segment that line
out of the image. Then you need to have an image with an object of
some known length in it, such as a ruler, so you can determine your
spatial calibration factor.

Subject: Image Processing- Length of a line

From: Karthik NV

Date: 14 Nov, 2010 14:31:03

Message: 5 of 24

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <f3bdace3-dcf9-4dc0-8981-69037d9fc19c@f16g2000vbz.googlegroups.com>...
> Forget about the length of the line on your computer screen - that is
> *totally* irrelevant. You DO want the pixel length of the line,
> unlike what you first said. Then you need to multiply this by your
> spatial calibration factor which is a number with units meters per
> pixel, or whatever actual length units you want. Then you'll have
> your answer. First of all you need to post your image somewhere so we
> can see it. Otherwise how can we tell you how to segment that line
> out of the image. Then you need to have an image with an object of
> some known length in it, such as a ruler, so you can determine your
> spatial calibration factor.

The spatial calibration factor is already known! Im working with a microstructure and the microscope already gives the scale factor.
I DO want the pixel length but not the total length of all pixels in the line, thats what i meant.
Can you tell me where i can put up my picture so that you can help me better? Thanks!

Subject: Image Processing- Length of a line

From: ImageAnalyst

Date: 14 Nov, 2010 14:40:17

Message: 6 of 24

I have no idea what this means:
"I DO want the pixel length but not the total length of all pixels in
the line, thats what i meant. "

I thought you wanted the total length of all pixels in the "line" or
along the skeleton of the line if the "line" actually has some
thickness. The "pixel length" - or the length of one pixel - which
you say you want is just the very same thing as your spatial
calibration factor, which you say you already have. You say you don't
want "total length of all pixels in the line' but like I said, I
thought that was *exactly* what you wanted (assuming length is just
that - length - and not area since you did say that the "lines"
actually had some area because they were 2-6 pixels wide).

Just do a web search for "free image hosting" and pick one. I don't
have a favorite yet since the best one out there just shut down, and
all the others have some hoops you have to jump through (like creating
an account).

Perhaps my image segmentation demo will help you:
http://www.mathworks.com/matlabcentral/fileexchange/25157

Subject: Image Processing- Length of a line

From: Karthik NV

Date: 14 Nov, 2010 16:33:03

Message: 7 of 24

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <c117ddf4-6d77-4ff8-b1ff-c376981e7374@o11g2000prf.googlegroups.com>...
> I have no idea what this means:
> "I DO want the pixel length but not the total length of all pixels in
> the line, thats what i meant. "
>
> I thought you wanted the total length of all pixels in the "line" or
> along the skeleton of the line if the "line" actually has some
> thickness. The "pixel length" - or the length of one pixel - which
> you say you want is just the very same thing as your spatial
> calibration factor, which you say you already have. You say you don't
> want "total length of all pixels in the line' but like I said, I
> thought that was *exactly* what you wanted (assuming length is just
> that - length - and not area since you did say that the "lines"
> actually had some area because they were 2-6 pixels wide).
>
> Just do a web search for "free image hosting" and pick one. I don't
> have a favorite yet since the best one out there just shut down, and
> all the others have some hoops you have to jump through (like creating
> an account).
>
> Perhaps my image segmentation demo will help you:
> http://www.mathworks.com/matlabcentral/fileexchange/25157

What i meant was that the thickness of the line varies and is not constant at all times. Hence the total no of pixels in a line does not give us an estimate of the length that we are looking for. Though if we could draw a skeleton line of 1 pixel thickness along the line we can count the number of pixels and get the length.

My understanding of spatial calibration factor is a scale which converts pixels into meters. And this is known from the microscope!

[url=http://www.freeimagehosting.net/][img]http://www.freeimagehosting.net/uploads/1a5c765ae5.jpg[/img][/url]

Here above is my image. Objectives are
1) To isolate or separate lines
2) To find out the length of each line. I have tried counting all the pixels that make up the line but that does not give me the actual length of the lines due to the thickness of the line.

Any inputs on how i can proceed are greatly appreciated. Thank you!
  

Subject: Image Processing- Length of a line

From: ImageAnalyst

Date: 14 Nov, 2010 17:30:08

Message: 8 of 24

I couldn't access your picture. It says it's not there. But
basically you can do this
1) get your snake-like object (thick wavy line), for example by
thresholding.
2) call bwlabel() to label your blobs
3) filter out blobs you don't want, for example based on area or
intensity
4) skeletonize what's left. You should have only the skeleton of the
"line" you want after this.
5) call regionprops or bwarea or similar. Or else call bwboundaries
or find() and go along the line counting up all the distances, which
will be either 1 or sqrt(2) as you move from one pixel to the next.

Subject: Image Processing- Length of a line

From: Karthik NV

Date: 14 Nov, 2010 18:11:03

Message: 9 of 24

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <ca1ae874-0298-49c2-907d-bd6ec62af069@42g2000prt.googlegroups.com>...
> I couldn't access your picture. It says it's not there. But
> basically you can do this
> 1) get your snake-like object (thick wavy line), for example by
> thresholding.
> 2) call bwlabel() to label your blobs
> 3) filter out blobs you don't want, for example based on area or
> intensity
> 4) skeletonize what's left. You should have only the skeleton of the
> "line" you want after this.
> 5) call regionprops or bwarea or similar. Or else call bwboundaries
> or find() and go along the line counting up all the distances, which
> will be either 1 or sqrt(2) as you move from one pixel to the next.

Sir,
Please try the link below to view the image. This image was obtained by scanning a color coded image and selecting only pixels of relevance which was then converted to a black and white image.

http://www.freeimagehosting.net/uploads/0a40994ecc.jpg

"4) Skeletonize whats left" I did not understand How exactly to do that?

Subject: Image Processing- Length of a line

From: ImageAnalyst

Date: 14 Nov, 2010 18:31:14

Message: 10 of 24

That looks like it's already been skeletonized. Not only that but it
looks like it's been shrunk down by subsampling quite a bit so that
many of the lines are broken now. This image looks like it now,
because of the broken lines, has hundreds and hundreds of lines. Why
don't you post the original grayscale image and the code you used to
binarize it?

What I meant for step 4 was that you skeletonize the blobs that remain
after you've done step 3. For example in step 3, maybe you have a
snake, a rectangle, and a disc. Then you determine (for example by
shape) that you don't want the rectangle and the disc so you filter
them out (using ismember like in my demo). So now you have an image
wit only the snake. Then you start step 4 where you skeletonize the
snake to get just a think single pixel wide path of pixels.

Subject: Image Processing- Length of a line

From: Sean de

Date: 15 Nov, 2010 15:47:03

Message: 11 of 24

"Karthik NV" <knadimpalli18@yahoo.co.in> wrote in message <ibp8nn$jfa$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <ca1ae874-0298-49c2-907d-bd6ec62af069@42g2000prt.googlegroups.com>...
> > I couldn't access your picture. It says it's not there. But
> > basically you can do this
> > 1) get your snake-like object (thick wavy line), for example by
> > thresholding.
> > 2) call bwlabel() to label your blobs
> > 3) filter out blobs you don't want, for example based on area or
> > intensity
> > 4) skeletonize what's left. You should have only the skeleton of the
> > "line" you want after this.
> > 5) call regionprops or bwarea or similar. Or else call bwboundaries
> > or find() and go along the line counting up all the distances, which
> > will be either 1 or sqrt(2) as you move from one pixel to the next.
>
> Sir,
> Please try the link below to view the image. This image was obtained by scanning a color coded image and selecting only pixels of relevance which was then converted to a black and white image.
>
> http://www.freeimagehosting.net/uploads/0a40994ecc.jpg
>
> "4) Skeletonize whats left" I did not understand How exactly to do that?

Perhaps this thread will be of interest to you:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/288187

Subject: Image Processing- Length of a line

From: Karthik NV

Date: 15 Nov, 2010 17:12:04

Message: 12 of 24

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <8a63e494-5fc7-4f23-bce5-6e31b6d42de8@m20g2000prc.googlegroups.com>...
> That looks like it's already been skeletonized. Not only that but it
> looks like it's been shrunk down by subsampling quite a bit so that
> many of the lines are broken now. This image looks like it now,
> because of the broken lines, has hundreds and hundreds of lines. Why
> don't you post the original grayscale image and the code you used to
> binarize it?
>
> What I meant for step 4 was that you skeletonize the blobs that remain
> after you've done step 3. For example in step 3, maybe you have a
> snake, a rectangle, and a disc. Then you determine (for example by
> shape) that you don't want the rectangle and the disc so you filter
> them out (using ismember like in my demo). So now you have an image
> wit only the snake. Then you start step 4 where you skeletonize the
> snake to get just a think single pixel wide path of pixels.

Sir,
I have uploaded my original picture here.

http://www.imagehousing.com/image/595235

In my very simple code I have selected a pixel range in this image(a range of r,g,b values) and then searched the entire image for that range and converted it into black and white which was the image i posted earlier.
My first question would be how do i make the broken lines continuous?
The black darker lines are what i am interested in. Now each of the lines has a thickness of a few pixels. How do i come up with the length a single pixel line which can be best fit to each of these lines?

I have started using the image processing toolbox very recently and i am going through your tutorial which looks helpful.

But I am unable to understand how you can skeletonize the image to a 1 pixel width. Can you please clarify on that?

My Objectives still remain as
1) Identifying and separating lines
2) Quantifying the line length.

Thank you.

Subject: Image Processing- Length of a line

From: ImageAnalyst

Date: 15 Nov, 2010 19:38:23

Message: 13 of 24

On Nov 15, 12:12 pm, "Karthik NV" <knadimpall...@yahoo.co.in> wrote:
> I have started using the image processing toolbox very recently and i am going through your tutorial which looks helpful.
> But I am unable to understand how you can skeletonize the image to a 1 pixel width. Can you please clarify on that?
-----------------------------------------------------------------------------

Use bwmorph() with the 'skel' option on your binary image.

Subject: Image Processing- Length of a line

From: Mihir Naik

Date: 16 Nov, 2010 03:02:04

Message: 14 of 24

"Karthik NV" <knadimpalli18@yahoo.co.in> wrote in message <ibodnd$np6$1@fred.mathworks.com>...
> I want to find the real length of a line in an image. By this i mean the length that we perceive with our eyes and not the pixel length.
> Here we are talking about complex shaped random lines that can be curves as well and these lines are anywhere from 2-6 pixels thick.
> Can someone plzzzz help me on how to do this in matlab? Thanks a lot.

Forget about going for one pixel width..........your images has all lines....forget about their thickness.........basically u wants to calculate length of that line....u are not worried about thickness......

use ginput().....and select two points one where line starts and other when it ends..,.....u will have two ordinates now (x1,y1) & (x2,y2)........calculate the distance using formula of coordinates....which will give u length in pixel ....u have to make sure that u will select the points which is in line for that go for edge pixel........

as u are saying u spatial factor....which will give u conversion of those picel length in to meters.............

Subject: Image Processing- Length of a line

From: ImageAnalyst

Date: 16 Nov, 2010 04:05:07

Message: 15 of 24

Alright, let's set aside all this talk about measuring lines in that
image and tell us what you want to measure. You *think* you want to
measure line length (whatever that means in this strange image)
because you think it will tell you what? *What* do you think the line
length represents? Do you think it represents the integrity of the
material? The stability of the material? The strength of the
material? the softness or hardness of the material? The bending
resistance? What exactly? What is the material? Maybe you really
could get by with the area fraction of the dark lines rather than the
ill-defined line length. But you need to provide me with the "big
picture."

Subject: Image Processing- Length of a line

From: Karthik NV

Date: 16 Nov, 2010 11:18:06

Message: 16 of 24

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <54125f3d-65af-45bd-ab7a-a1a178fb8d75@h21g2000vbh.googlegroups.com>...
> Alright, let's set aside all this talk about measuring lines in that
> image and tell us what you want to measure. You *think* you want to
> measure line length (whatever that means in this strange image)
> because you think it will tell you what? *What* do you think the line
> length represents? Do you think it represents the integrity of the
> material? The stability of the material? The strength of the
> material? the softness or hardness of the material? The bending
> resistance? What exactly? What is the material? Maybe you really
> could get by with the area fraction of the dark lines rather than the
> ill-defined line length. But you need to provide me with the "big
> picture."

Let me give you the Big picture and how i have hit a road block.
The lines in the image are of two types
1) Lines which are a part of a network
2) Lines which are separate or broken from the network
If more lines are a part of the network it affects the strength of the material.
The more the length of an extended network, easier it is for crack propagation.
Hence Line length is the first step in quantifying the network.

The next step would be to separate the lines from the network and study them. If we know the the starting and ending points of each line then we can look at interactions in the network where two or more lines meet. (This can be studied from the original colored image where interactions between lines sometimes leads different colored pixels)

My initial approach was to start at any point and and search for the 8 pixels around it and keep progressing till we reach an end point.The Problems are
1) Just selecting an rgb range is giving me a lot of discontinuities. Is there a better way of selecting only the black lines from my image to get a more realistic network?
2) This kind of searching gives me more of an area and not the length of the line.
3) Also i am unable to *clearly define and store each line separately*

Coming to what i am expecting when i mean line length is For example if i take a 100 by 100 image and draw a line along its diagonal in paint, the length i want to get is close to 100*sqrt(2) pixels and if i draw a circle inside this 100 by 100 i want to calculate the circumference of the circle to be Pi*100 pixels.

Subject: Image Processing- Length of a line

From: ImageAnalyst

Date: 16 Nov, 2010 11:47:31

Message: 17 of 24

I think bwarea should give you very close to what you want. See this
demo:
a=logical(eye(7))
area = bwarea(a)
length = 6 * sqrt(2)
a =

     1 0 0 0 0 0 0
     0 1 0 0 0 0 0
     0 0 1 0 0 0 0
     0 0 0 1 0 0 0
     0 0 0 0 1 0 0
     0 0 0 0 0 1 0
     0 0 0 0 0 0 1


area =

    8.5000


length =

    8.4853

I think just looking at what you got should be a good indicator. It
gets more complicated if you have to try to extend lines to connect
them, and I really don't know if that would be any more accurate
indicator than just leaving them alone. As far as enhancing lines,
there are lots of methods out there. Just search around. Maybe also
look for ridge and valley detection.

So did you look at the link Sean gave you? He says he's looked at
cracks in concrete before.

Subject: Image Processing- Length of a line

From: Sean de

Date: 16 Nov, 2010 15:44:05

Message: 18 of 24

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <c268771a-d541-
> So did you look at the link Sean gave you? He says he's looked at
> cracks in concrete before.

The images in that thread look really similar to the ones in this thread:
http://drop.io/onepixelline
and accurate results for the OP's, pretty much identical, request were recovered.

It's really going to ruin these old threads when drop.io goes down in a month.

Subject: Image Processing- Length of a line

From: Karthik NV

Date: 16 Nov, 2010 17:02:06

Message: 19 of 24

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ibu8s4$3io$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <c268771a-d541-
> > So did you look at the link Sean gave you? He says he's looked at
> > cracks in concrete before.
>
> The images in that thread look really similar to the ones in this thread:
> http://drop.io/onepixelline
> and accurate results for the OP's, pretty much identical, request were recovered.
>
> It's really going to ruin these old threads when drop.io goes down in a month.

Hi sean, I cant seem to access those files! Drop.io has already gone down...
If you did download them and the code along with it, please mail it to knadimpalli18@gmail.com

The other link which you posted is helpful and i am going through it, Thanks :)

 

Subject: Image Processing- Length of a line

From: Sean de

Date: 16 Nov, 2010 17:12:04

Message: 20 of 24

"Karthik NV" <knadimpalli18@yahoo.co.in> wrote in message <ibuded$5b5$1@fred.mathworks.com>...
> "Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ibu8s4$3io$1@fred.mathworks.com>...
> > ImageAnalyst <imageanalyst@mailinator.com> wrote in message <c268771a-d541-
> > > So did you look at the link Sean gave you? He says he's looked at
> > > cracks in concrete before.
> >
> > The images in that thread look really similar to the ones in this thread:
> > http://drop.io/onepixelline
> > and accurate results for the OP's, pretty much identical, request were recovered.
> >
> > It's really going to ruin these old threads when drop.io goes down in a month.
>
> Hi sean, I cant seem to access those files! Drop.io has already gone down...
> If you did download them and the code along with it, please mail it to knadimpalli18@gmail.com
>
> The other link which you posted is helpful and i am going through it, Thanks :)
>
>

I'm glad!

If you click on this link, it's the first image (white with black lines).
http://drop.io/onepixelline

It still works here (US) at least...

Subject: Image Processing- Length of a line

From: Karthik NV

Date: 17 Nov, 2010 13:06:04

Message: 21 of 24

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <0b9a0b4d-f9f5-43b9-8af5-9fa195d39f6d@u8g2000vby.googlegroups.com>...
> On Nov 15, 12:12 pm, "Karthik NV" <knadimpall...@yahoo.co.in> wrote:
> > I have started using the image processing toolbox very recently and i am going through your tutorial which looks helpful.
> > But I am unable to understand how you can skeletonize the image to a 1 pixel width. Can you please clarify on that?
> -----------------------------------------------------------------------------
>
> Use bwmorph() with the 'skel' option on your binary image.
>
Sir,
While using Skel option i am getting the following error.

??? Error using ==> iptcheckinput
Function BWMORPH expected its first input, BW, to be two-dimensional.

Error in ==> bwmorph at 91
iptcheckinput(a,{'numeric' 'logical'},{'real' 'nonsparse' '2d'}, ...

Subject: Image Processing- Length of a line

From: ImageAnalyst

Date: 17 Nov, 2010 13:14:12

Message: 22 of 24

On Nov 17, 8:06 am, "Karthik NV" <knadimpall...@yahoo.co.in> wrote:
> Sir,
> While using Skel option i am getting the following error.
> ??? Error using ==> iptcheckinput
> Function BWMORPH expected its first input, BW, to be two-dimensional.
> Error in ==> bwmorph at 91
> iptcheckinput(a,{'numeric' 'logical'},{'real' 'nonsparse' '2d'}, ...
-------------------------------------------------------------------------------------------------
Then you used it incorrectly. You probably passed it either a 1D
vector or a 3D color image. What more can we say given what you've
provided?

Subject: Image Processing- Length of a line

From: Karthik NV

Date: 17 Nov, 2010 13:50:05

Message: 23 of 24

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <5406dbb7-47fe-4773-81bb-7df13ff5c5df@j25g2000yqa.googlegroups.com>...
> On Nov 17, 8:06 am, "Karthik NV" <knadimpall...@yahoo.co.in> wrote:
> > Sir,
> > While using Skel option i am getting the following error.
> > ??? Error using ==> iptcheckinput
> > Function BWMORPH expected its first input, BW, to be two-dimensional.
> > Error in ==> bwmorph at 91
> > iptcheckinput(a,{'numeric' 'logical'},{'real' 'nonsparse' '2d'}, ...
> -------------------------------------------------------------------------------------------------
> Then you used it incorrectly. You probably passed it either a 1D
> vector or a 3D color image. What more can we say given what you've
> provided?

I just realized that when i pass it off as a 2D matrix it accepts it!
Its my bad, When i used imread on my stored binary image i wrongly thought that it will give me a 2D matrix.

Subject: Image Processing- Length of a line

From: ImageAnalyst

Date: 17 Nov, 2010 14:06:55

Message: 24 of 24

On Nov 17, 8:50 am, "Karthik NV" <knadimpall...@yahoo.co.in> wrote:
> I just realized that when i pass it off as a 2D matrix it accepts it!
> Its my bad, When i used imread on my stored binary image i wrongly thought that it will give me a 2D matrix.
---------------------------------------------------------------------------------------------------
Yes,it will accept 2D images - that's what it wants.
imread will read it in as whatever it was stored as. If you didn't
store it as a 2D image, then it will read back whatever you stored (I
think) and not do some conversion to 2D. After all, how would it know
the manner in which to convert to 2D? There could be lots of ways to
convert a 1D or 3D image to 2D.

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