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:
morphology and spur

Subject: morphology and spur

From: ventus85

Date: 17 Nov, 2010 09:19:03

Message: 1 of 10

Good morning,
this is my picture http://img696.imageshack.us/img696/852/16144359.png
I have to remove the pixels in the isolated branches, but using the function "spur" I get this result http://img219.imageshack.us/img219/61/14417424.png
Why?
What can I use?
Thank's!

Subject: morphology and spur

From: ventus85

Date: 17 Nov, 2010 17:16:04

Message: 2 of 10

Let me explain: I want to remove those branches that are in the middle and are not part of the contours.

Thanks.

"ventus85 " <ventus85@katamail.com> wrote in message <ic06m7$3gk$1@fred.mathworks.com>...
> Good morning,
> this is my picture http://img696.imageshack.us/img696/852/16144359.png
> I have to remove the pixels in the isolated branches, but using the function "spur" I get this result http://img219.imageshack.us/img219/61/14417424.png
> Why?
> What can I use?
> Thank's!

Subject: morphology and spur

From: Sean de

Date: 17 Nov, 2010 18:21:03

Message: 3 of 10

"ventus85 " <ventus85@katamail.com> wrote in message <ic12kk$4cv$1@fred.mathworks.com>...
> Let me explain: I want to remove those branches that are in the middle and are not part of the contours.
>
> Thanks.
>
> "ventus85 " <ventus85@katamail.com> wrote in message <ic06m7$3gk$1@fred.mathworks.com>...
> > Good morning,
> > this is my picture http://img696.imageshack.us/img696/852/16144359.png
> > I have to remove the pixels in the isolated branches, but using the function "spur" I get this result http://img219.imageshack.us/img219/61/14417424.png
> > Why?
> > What can I use?
> > Thank's!

Your image is rgb (at least when I save it) so you can't use it with bwmorph.
Convert it to logical:
I = rgb2gray(imread('your_image.png'))>230;

Now you can use bwmorph

Subject: morphology and spur

From: ImageAnalyst

Date: 17 Nov, 2010 18:24:26

Message: 4 of 10

Post your code.

Subject: morphology and spur

From: ventus85

Date: 17 Nov, 2010 21:49:27

Message: 5 of 10

This is the code:

img=imread('contours1.jpg');
img2=img(:,:,1);
figure, imshow(img2)
e=bwmorph(img2,'spur');
figure, imshow(e)


contours1.jpg -->http://img696.imageshack.us/img696/852/16144359.png
e --> http://img219.imageshack.us/img219/61/14417424.png

The line of code
img2=img(:,:,1);
is necessary because the function bwmorph expected its first input to be two dimensional.

thanks

Subject: morphology and spur

From: Sean de

Date: 17 Nov, 2010 22:12:04

Message: 6 of 10

"ventus85 " <ventus85@katamail.com> wrote in message <ic1il7$i8g$1@fred.mathworks.com>...
> This is the code:
>
> img=imread('contours1.jpg');
> img2=img(:,:,1);
> figure, imshow(img2)
> e=bwmorph(img2,'spur');
> figure, imshow(e)
>
>
> contours1.jpg -->http://img696.imageshack.us/img696/852/16144359.png
> e --> http://img219.imageshack.us/img219/61/14417424.png
>
> The line of code
> img2=img(:,:,1);
> is necessary because the function bwmorph expected its first input to be two dimensional.
>
> thanks

And it will be two dimensional. But it won't be black and white (BWMORPH - the BW is black and white.)

if you do:
unique(img2)
you'll see how many numbers the are. That's why you have to binarize it with a threshold.
img3 = img2>230;

Subject: morphology and spur

From: ventus85

Date: 17 Nov, 2010 23:57:05

Message: 7 of 10

Thanks for your tips!

img=imread('contours1.jpg');
img2 = rgb2gray(img)>230;
e=bwmorph(img2,'spur');

I apply three times the morphological, I get this image http://img4.imageshack.us/img4/5879/34444.png

Instead I would get something like this image
http://img821.imageshack.us/img821/3723/desidero.jpg

> And it will be two dimensional. But it won't be black and white (BWMORPH - the BW is
> black and white.)

You're right! I had not thought of that!

I'm sorry, but I did not understand the reason for the function unique.
Unique find unique elements of vector, this is right but why use a threshold?

Subject: morphology and spur

From: ventus85

Date: 18 Nov, 2010 10:53:05

Message: 8 of 10

I used bwareaopen.

M=10;
img=imread('contours1.jpg');
img2 = rgb2gray(img)>230;

g=zeros(size(img2));
g(find(img2>0.2))=1;
h=bwareaopen(g,M);
figure;imshow(h);


I get the result I wanted, but...the use of the parameter M is not optimal, who tells me he will always be 10?

Subject: morphology and spur

From: ImageAnalyst

Date: 18 Nov, 2010 11:13:41

Message: 9 of 10

On Nov 18, 5:53 am, "ventus85 " <ventu...@katamail.com> wrote:
> I used bwareaopen.
>
> M=10;
> img=imread('contours1.jpg');
> img2 = rgb2gray(img)>230;
>
> g=zeros(size(img2));
> g(find(img2>0.2))=1;
> h=bwareaopen(g,M);
> figure;imshow(h);
>
> I get the result I wanted, but...the use of the parameter M is not optimal, who tells me he will always be 10?

--------------------------------------------------------------------------------------------
No one tells you that. You told yourself. You have to pick
something. Maybe it always will be some constant number for your
images (it usually is) but if you want it to vary then you can develop
some algorithm to specify how it varies according to the content of
each image.

Subject: morphology and spur

From: ventus85

Date: 18 Nov, 2010 11:46:04

Message: 10 of 10

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <60242809-140d-49dc-bf33-fd6b03b69e02@o34g2000vbi.googlegroups.com>...
> --------------------------------------------------------------------------------------------
> No one tells you that. You told yourself. You have to pick
> something. Maybe it always will be some constant number for your
> images (it usually is) but if you want it to vary then you can develop
> some algorithm to specify how it varies according to the content of
> each image.

Thank you.

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