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

Subject: image processing

From: misty m.

Date: 30 Mar, 2008 11:06:02

Message: 1 of 16

hi,
i've got a problem with an image. You can take a look at
the image here: http://test-bone.pl.tl/

it is an image of a bone with few drilled holes (You can
see 3 drilled holes on the left side of a bone). i must
find edges of these holes (actually the middle one) using
matlab function 'edge' but because of these cracks i cannot.
can You please suggest me some operation i can do on this
image to get rid of these crakcs so i can find edges of
these holes?

kind regards
 

Subject: image processing

From: Vikram

Date: 30 Mar, 2008 11:58:01

Message: 2 of 16

"misty m." <donotspam@smth.be> wrote in message
<fsns6q$ke7$1@fred.mathworks.com>...
> hi,
> i've got a problem with an image. You can take a look at
> the image here: http://test-bone.pl.tl/
>
> it is an image of a bone with few drilled holes (You can
> see 3 drilled holes on the left side of a bone). i must
> find edges of these holes (actually the middle one) using
> matlab function 'edge' but because of these cracks i cannot.
> can You please suggest me some operation i can do on this
> image to get rid of these crakcs so i can find edges of
> these holes?
>
> kind regards
>
I can see you are into medical imaging, you present an
interesting conundrum, maybe you can convert the image to a
negative image, there by making all dark pixels white and
white pixels dark, if you do that, you will see that the
'hole' in your image is very prominent, then you may proceed
to detect the edges - which I have no clue about.
the formula for that is , negativepix = 255 -
TrueIntensityOfAPixel(process these elements using a formula).

Subject: image processing

From: misty m.

Date: 30 Mar, 2008 16:07:02

Message: 3 of 16

unfortunately, making a negative won't help :/
any other ideas?

Subject: image processing

From: Bryan Babcock

Date: 30 Mar, 2008 16:15:03

Message: 4 of 16

I would try using:

filter = fspecial('average',n);
filteredimg = imfilter(originalimg,filter,'replicate');

where n is an n-by-n pixel region you average over. The
result is a 'smeared' image. Play around with the size of n
to see how big you have to make it for the cracks to be
smeared out.


"misty m." <donotspam@smth.be> wrote in message
<fsodr6$11e$1@fred.mathworks.com>...
> unfortunately, making a negative won't help :/
> any other ideas?
>
>

Subject: image processing

From: misty m.

Date: 30 Mar, 2008 17:24:02

Message: 5 of 16

still impossible.. :/ i'm trying with different 'n' but the
best i got is half od edges of my hole..

Subject: image processing

From: ImageAnalyst

Date: 31 Mar, 2008 01:09:35

Message: 6 of 16

On Mar 30, 1:24=A0pm, "misty m." <donots...@smth.be> wrote:
> still impossible.. :/ i'm trying with different 'n' but the
> best i got is half od edges of my hole..
----------------------------------------------------

misty.m
Are you allowed to manually edit the image beforehand (like you're
just analyzing a few dozen images) or does it need to be totally
automated (because, for example, you need to process thousands of
images)?

Also it's hard to design a robust algorithm based on just one photo
because invalid assumptions could be made (like the holes will always
be on the left edge of the image or they always have the same
intensity or things like that). You might want to consider posting
more images, otherwise the best we can do is to solve it for one image
but that may fail miserably in general because it was specialized for
just that one particular image.
Regards,
ImageAnalyst

By the way, misty, you should have started a new thread rather than
reply to Raymond's posting which in turn should have also been a new
thread rather than continuing on with muhammad's original thread.

Subject: image processing

From: Vihang Patil

Date: 31 Mar, 2008 05:55:02

Message: 7 of 16

"misty m." <donotspam@smth.be> wrote in message <fsns6q$ke7
$1@fred.mathworks.com>...
> hi,
> i've got a problem with an image. You can take a look at
> the image here: http://test-bone.pl.tl/
>
> it is an image of a bone with few drilled holes (You can
> see 3 drilled holes on the left side of a bone). i must
> find edges of these holes (actually the middle one)
using
> matlab function 'edge' but because of these cracks i
cannot.
> can You please suggest me some operation i can do on
this
> image to get rid of these crakcs so i can find edges of
> these holes?
>
> kind regards
>
Just a suggestion.
How about using Hough Lines to detect the circular portion?
Once these circles are detected you can use the edge
function.
HTH
Vihang

Subject: image processing

From: misty m.

Date: 31 Mar, 2008 07:58:01

Message: 8 of 16

ImageAnalyst:

edges must be find automaticly. these pictures are CT scans
of a bone with drilled holes. images from 'the beginning'
and from 'the end' of hole aren't so bad, they do not have
so many cracks and i've got an algorithm that find edges in
them.

problem starts with images from 'the middle' of the bone -
they have a lot of cracks. i tried some filter but as i
posted before nothing helps.
i put few more pictures: http://test-bone.pl.tl/

what do You think of them?


Vihang Patil:

shame to say but i do not know how :| as i look at matlab
help it is written for example:
I = imread('circuit.tif');
       rotI = imrotate(I,33,'crop');
       BW = edge(rotI,'canny');
       [H,T,R] = hough(BW);

so at first i need to 'edge' image..
but maybe i should read it more carefuly

Subject: image processing

From: Sven

Date: 31 Mar, 2008 08:47:01

Message: 9 of 16

"misty m." <donotspam@smth.be> wrote in message
<fsq5i9$b92$1@fred.mathworks.com>...
> ImageAnalyst:
>
> edges must be find automaticly. these pictures are CT scans
> of a bone with drilled holes. images from 'the beginning'
> and from 'the end' of hole aren't so bad, they do not have
> so many cracks and i've got an algorithm that find edges in
> them.
>
> problem starts with images from 'the middle' of the bone -
> they have a lot of cracks. i tried some filter but as i
> posted before nothing helps.
> i put few more pictures: http://test-bone.pl.tl/
>
> what do You think of them?
>
>
> Vihang Patil:
>
> shame to say but i do not know how :| as i look at matlab
> help it is written for example:
> I = imread('circuit.tif');
> rotI = imrotate(I,33,'crop');
> BW = edge(rotI,'canny');
> [H,T,R] = hough(BW);
>
> so at first i need to 'edge' image..
> but maybe i should read it more carefuly
>
>

Hi Vihang,

What is the output that you are looking for? For example,
it seems that all of your holes are always (very close to)
the same diameter, and always (very close to) perfectly
circular. Therefore, is your desired output is simply a
[row column] coordinate pair per hole? This coordinate
gives you the centre of your hole, and from this you already
know the hole radius, such that you don't *necessarily* need
to find the hole edges.

The following blog gives a few very useful examples of how
you can find round objects in an image:
http://basic-eng.blogspot.com/2005/10/detecting-objects-shapei-round-object.html

There are other topics as well that you will find useful.

I think that one common point that people are making for you
is this:
It is very difficult to simply find the circle *directly*
from the raw images that you have posted to web. However,
there are quite a few processing steps you can take to make
it much easier to find the circular holes. Here are a few
of my suggestions:

1. Use the results you get at the 'ends' to help predict
where the holes will be in 'the middle' slices. Perhaps the
holes should not move more than a certain distance from one
slice to the next? Using this, you can narrow your search area.

2. Theshold. It may just be a trick of the light, but it
seems that the holes themselves are *slightly* blacker than
the soft parts of the bones. Maybe if you threshold
(newImage = oldImage<threshold_value) very close to this
'black', you will be able to reduce the input to just a few
blobs.

3. bwmorph. If the above thresholding can't produce perfect
circles, I bet its result can be improved by the following:
- You know the hole radius (maybe, say, 8 pixels)
- If you first threshold for the black regions, and then run
an "erode" morph of, say, 5 pixels, you will clear away any
of the non-hole black areas.

4. Filters. As some other posters have mentioned, some
averaging filters can transform your raw image into another
image that is easier to run detection algorithms. You say
above that you've tried filtering and "nothing helps". It
is true that there is no such thing as a "black circle in an
image with other black cells" filter, but many of the
filters *will* help to transform you image, step by step,
into one that becomes easier and easier to work with.

Hope this helps.

Cheers,
Sven.

Subject: image processing

From: Sven

Date: 31 Mar, 2008 09:13:01

Message: 10 of 16

"Sven " <sven.holcombe@gmail.deleteme.com> wrote in message
<fsq8e5$a8l$1@fred.mathworks.com>...
> "misty m." <donotspam@smth.be> wrote in message
> <fsq5i9$b92$1@fred.mathworks.com>...
> > ImageAnalyst:
> >
> > edges must be find automaticly. these pictures are CT scans
> > of a bone with drilled holes. images from 'the beginning'
> > and from 'the end' of hole aren't so bad, they do not have
> > so many cracks and i've got an algorithm that find edges in
> > them.
> >
> > problem starts with images from 'the middle' of the bone -
> > they have a lot of cracks. i tried some filter but as i
> > posted before nothing helps.
> > i put few more pictures: http://test-bone.pl.tl/
> >
> > what do You think of them?
> >
> >
> > Vihang Patil:
> >
> > shame to say but i do not know how :| as i look at matlab
> > help it is written for example:
> > I = imread('circuit.tif');
> > rotI = imrotate(I,33,'crop');
> > BW = edge(rotI,'canny');
> > [H,T,R] = hough(BW);
> >
> > so at first i need to 'edge' image..
> > but maybe i should read it more carefuly
> >
> >
>
> Hi Vihang,
>
> What is the output that you are looking for? For example,
> it seems that all of your holes are always (very close to)
> the same diameter, and always (very close to) perfectly
> circular. Therefore, is your desired output is simply a
> [row column] coordinate pair per hole? This coordinate
> gives you the centre of your hole, and from this you already
> know the hole radius, such that you don't *necessarily* need
> to find the hole edges.
>
> The following blog gives a few very useful examples of how
> you can find round objects in an image:
>
http://basic-eng.blogspot.com/2005/10/detecting-objects-shapei-round-object.html
>
> There are other topics as well that you will find useful.
>
> I think that one common point that people are making for you
> is this:
> It is very difficult to simply find the circle *directly*
> from the raw images that you have posted to web. However,
> there are quite a few processing steps you can take to make
> it much easier to find the circular holes. Here are a few
> of my suggestions:
>
> 1. Use the results you get at the 'ends' to help predict
> where the holes will be in 'the middle' slices. Perhaps the
> holes should not move more than a certain distance from one
> slice to the next? Using this, you can narrow your search
area.
>
> 2. Theshold. It may just be a trick of the light, but it
> seems that the holes themselves are *slightly* blacker than
> the soft parts of the bones. Maybe if you threshold
> (newImage = oldImage<threshold_value) very close to this
> 'black', you will be able to reduce the input to just a few
> blobs.
>
> 3. bwmorph. If the above thresholding can't produce perfect
> circles, I bet its result can be improved by the following:
> - You know the hole radius (maybe, say, 8 pixels)
> - If you first threshold for the black regions, and then run
> an "erode" morph of, say, 5 pixels, you will clear away any
> of the non-hole black areas.
>
> 4. Filters. As some other posters have mentioned, some
> averaging filters can transform your raw image into another
> image that is easier to run detection algorithms. You say
> above that you've tried filtering and "nothing helps". It
> is true that there is no such thing as a "black circle in an
> image with other black cells" filter, but many of the
> filters *will* help to transform you image, step by step,
> into one that becomes easier and easier to work with.
>
> Hope this helps.
>
> Cheers,
> Sven.
>

Here's a starting point for you that illustrates *one*
approach. It worked for me on your first example image.
It's up to you to choose the best method, and adapt it to
suit all your input cases.

I = imread('your_first_image.bmp');
BW = I < 25; % Threshold

se = strel('disk',14); % A disc of 14 pixels, used to wipe
away unwanted pixels
BW_2 = bwmorph(BW,'erode',6); % Blobs that survived the
'disc wipe'

L = bwlabel(BW_2); % A matrix with all separate blobs labelled
stats= regionprops(L,'Area','Centroid'); % Get the area and
centroid of each blob

valid_indexes = [stats.Area] < 2000; % Indexes of blobs that
are less than 2000 pixels (as we expect the holes to be)

stats(valid_indexes).Centroid % The coordinate(s)of the
holes(s) in the image.

----

Note that in the above, there were many steps to 'improve'
the image so it was easier to detect black/white regions.
Pattern detection very rarely works on the original image.

Cheers,
Sven.

Subject: image processing

From: misty m.

Date: 31 Mar, 2008 12:41:04

Message: 11 of 16

i took a look on Your code, modyfied it a little. now i've
got smth like that-i search for the biggest holes, i've got
it's centroids (as i understad middle of each hole), i
check which one is the closest to the middle of an image
and i've got a centroid of my hole.
but still-it is only a centroid, not a hole. how i can
paint it to find edges?

Subject: image processing

From: ImageAnalyst

Date: 31 Mar, 2008 13:56:56

Message: 12 of 16

On Mar 31, 8:41=A0am, "misty m." <donots...@smth.be> wrote:
> i took a look on Your code, modyfied it a little. now i've
> got smth like that-i search for the biggest holes, i've got
> it's centroids (as i understad middle of each hole), i
> check which one is the closest to the middle of an image
> and i've got a centroid of my hole.
> but still-it is only a centroid, not a hole. how i can
> paint it to find edges?
----------------------------------------------------------------------------=
----
misty.m:
Don't use the arguments like he told you to, except for the labeled
image argument. Just call stats=3D regionprops(L); This will get you
everything. You can then examine the circularity (=3D perimeter squared
divided by the area) to find roughly circular blobs. Then use
PixelIdxList to erase all other non-circular blobs from your image.
Then use bwboundaries() to find the boundaries of just the remaining
round objects. What do you do about the holes cut off at the edge of
the image? I'd just ignore them since you don't have the complete
hole. You might want to find some way to model your background since
it does not seem to be uniform and this messes up your thresholding.

What is "smth"? A typo? An acronym? Something else?
Also, your posts are getting a bit sloppy and hard to read (spelling,
capitalization, punctuation) -- please re-read them first before
posting.
And you might find better help in sci.image.processing, but you might
not get MATLAB code from there as they use a variety of packages.
Regards,
ImageAnalyst

Subject: image processing

From: misty m.

Date: 31 Mar, 2008 14:02:05

Message: 13 of 16

i've found some other options for 'regionprops',
with 'FilledImage' i can get my hole, but becuse of earlier
operations i've lost too much information and the shape of
the hole is not acceptable :/

Subject: image processing

From: Sven

Date: 1 Apr, 2008 00:21:03

Message: 14 of 16

"misty m." <donotspam@smth.be> wrote in message
<fsqqst$4jr$1@fred.mathworks.com>...
> i've found some other options for 'regionprops',
> with 'FilledImage' i can get my hole, but becuse of earlier
> operations i've lost too much information and the shape of
> the hole is not acceptable :/

I believe my previous paragraph still stands unanswered.
----
What is the output that you are looking for? For example,
it seems that all of your holes are always (very close to)
the same diameter, and always (very close to) perfectly
circular. Therefore, is your desired output is simply a
[row column] coordinate pair per hole? This coordinate
gives you the centre of your hole, and from this you already
know the hole radius, such that you don't *necessarily* need
to find the hole edges.
----
I hope that you realise how simple it would be to simply
*draw* a circle on your picture if you know the central
point and radius of the hole.

Thanks,
Sven.

Subject: image processing

From: misty m.

Date: 1 Apr, 2008 08:17:02

Message: 15 of 16

oh, sorry.

the output i'm looking for are edges of the middle drilled
circle. when i have edges, i can simply find coeffiecents -
and this is the main output.

these drilled holes are not circles. they may look like,
but actually they are closer to elipse. when i'll have the
coeffiecents of edges then i'll use spline to describe
these elipse. unfortunately i cannot put a circle on it (as
You suggestet before).

thanks for all Your suggestions!

misty

Subject: image processing

From: Bryan

Date: 3 Apr, 2008 06:25:04

Message: 16 of 16

"misty m." <donotspam@smth.be> wrote in message
<fssr1u$2rr$1@fred.mathworks.com>...
> oh, sorry.
>
> the output i'm looking for are edges of the middle drilled
> circle. when i have edges, i can simply find coeffiecents -
> and this is the main output.
>
> these drilled holes are not circles. they may look like,
> but actually they are closer to elipse. when i'll have the
> coeffiecents of edges then i'll use spline to describe
> these elipse. unfortunately i cannot put a circle on it (as
> You suggestet before).
>
> thanks for all Your suggestions!
>
> misty

whether they are exactly circular or not is irrelevant... it
is equally easy to draw an ellipse. but probably drawing
isn't what you're after anyway.

the 'regionprops' function includes possible outputs of
'eccentricity', 'majorAxisLength' and 'minorAxisLength'
which should help you tremendously.

if you don't like how your filtered-image hole looks, use
the coordinates of the filtered one, index back into the raw
image, and use 'imfill' to try and fill it in... wash,
rinse, repeat. but, as already stated, your raw image is
probably too noisy to get a good measure of the hole
properties without filtering in some way.


bryan

Tags for this Thread

No tags are associated with 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