MATLAB Answers

change the output representation

Asked by Elysi Cochin on 21 Mar 2013

In this code for convex hull.... the output image has a white border around the image.... as i have shown in the link....

http://img96.imageshack.us/img96/2201/27264487.png

what should i do to the code so that i dont want the border.... i want the output as

http://img189.imageshack.us/img189/797/93334960.png

The code i used is...

    function convexhull
    a=imread('impcon.bmp');
    a=a(:,:,3);
    o=a;
    subplot(2,2,1)
    imshow(o)
    title('original image');
    [r,c]=size(a);
    c=[1 0 0;1 0 0;1 0 0 ] 
    c1=[1 1 1;0 0 0;0 0 0 ];
    c2=[0 0 1; 0 0 1;0 0 1];
    c3=[0 0 0;0 0 0;1 1 1];
    b=a;
    for u=1:10
    d=(imerode(b,c))|a;
    if(b==d)
    break;
    end
    b=d;
    end
    %-------------
    m=a;
    for u=1:10
    n=(imerode(m,c1))|a;
    if(m==n)
    break;
    end
    m=n;
    end
    %-------------
    p=a;
    for u=1:10
    l=(imerode(p,c2))|a;
    if(p==l)
    break;
    end
    p=l;
    end
    %-------------
    z=a;
    for u=1:10
    v=(imerode(z,c3))|a;
    if(z==v)
    break;
    end
    z=v;
    end
    %-------------
    H=z|p|m|b;
    subplot(2,2,2)
    imshow(H)
    title('convex Hull of image');

Please show me where to change the code.... so that i get the output as shown in the second link.....please do reply....

  0 Comments

Products

No products are associated with this question.

1 Answer

Answer by Image Analyst
on 21 Mar 2013
 Accepted answer

Why aren't you using bwconvhull()? If you don't have a new enough version, then you can use imclearborder() to get rid of foreground touching the border.

  2 Comments

Elysi Cochin on 21 Mar 2013

thank u sir.... i used imclearborder()

Image Analyst
on 21 Mar 2013

You're welcome, though it's not the preferred solution - bwconvhull() is.


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply today