Anda di halaman 1dari 8

3/18/13

Image Processing Toolbox - Texture Segmentation Using Texture Filters Demo - MathWorks India
India Accelerating the pace of engineering and science Create Account Log In Contact Us Store

Products & Services Products & Services

Solutions

Academ ia

Support

User Com m unity

Events

Com pany

Image Processing Toolbox

Videos & Examples

Image Processing Toolbox


Texture Segmentation Using Texture Filters
Texture segmentation is the identification of regions based on their texture. Your goal is to segment two kinds of fabric in an image using texture filters. TRY OR BUY

Share

Contact Sales Product Trial Pricing and Licensing

Contents
Step 1: Read Image Step 2: Create Texture Image Step 3: Create Rough Mask for the Bottom Texture Step 4: Use Rough Mask to Segment the Top Texture Step 5: Display Segmentation Results Using Other Texture Filters in Segmentation

Step 1: Read Image


Read in b a g . p n g .

I=i m r e a d ( ' b a g . p n g ' ) ; f i g u r e ,i m s h o w ( I ) ;

Step 2: Create Texture Image


Use e n t r o p y f i l tto create a texture image. The function e n t r o p y f i l treturns an array where each output pixel contains the entropy value of the 9-by-9 neighborhood around the corresponding pixel in the input image I . Entropy is a statistical measure of randomness.

E=e n t r o p y f i l t ( I ) ;

Use m a t 2 g r a yto rescale the texture image Eso that its values are in the default range for a double image.

E i m=m a t 2 g r a y ( E ) ; i m s h o w ( E i m ) ;

www.mathworks.in/products/image/examples.html?file=/products/demos/shipping/images/ipextexturefilter.html#1

1/8

3/18/13

Image Processing Toolbox - Texture Segmentation Using Texture Filters Demo - MathWorks India

Step 3: Create Rough Mask for the Bottom Texture


Threshold the rescaled image E i mto segment the textures. A threshold value of 0.8 is selected because it is roughly the intensity value of pixels along the boundary between the textures.

B W 1=i m 2 b w ( E i m ,. 8 ) ;

i m s h o w ( B W 1 ) ; f i g u r e ,i m s h o w ( I ) ;

The segmented objects in the binary image B W 1are white. If you compare B W 1to I , you notice the top texture is overly

www.mathworks.in/products/image/examples.html?file=/products/demos/shipping/images/ipextexturefilter.html#1

2/8

3/18/13
texture using b w a r e a o p e n .

Image Processing Toolbox - Texture Segmentation Using Texture Filters Demo - MathWorks India

segmented (multiple white objects) and the bottom texture is segmented almost in its entirety. You can extract the bottom

B W a o=b w a r e a o p e n ( B W 1 , 2 0 0 0 ) ; i m s h o w ( B W a o ) ;

Use i m c l o s eto smooth the edges and to close any open holes in the object in B W a o . A 9-by-9 neighborhood is selected because this neighborhood was also used by e n t r o p y f i l t .

n h o o d=t r u e ( 9 ) ; c l o s e B W a o=i m c l o s e ( B W a o , n h o o d ) ; i m s h o w ( c l o s e B W a o )

Use i m f i l lto fill holes in the object in c l o s e B W a o .

r o u g h M a s k=i m f i l l ( c l o s e B W a o , ' h o l e s ' ) ;

Step 4: Use Rough Mask to Segment the Top Texture


Compare the binary image r o u g h M a s kto the original image I . Notice the mask for the bottom texture is not perfect because the mask does not extend to the bottom of the image. However, you can use r o u g h M a s kto segment the top texture.

i m s h o w ( r o u g h M a s k ) ; f i g u r e ,i m s h o w ( I ) ;

www.mathworks.in/products/image/examples.html?file=/products/demos/shipping/images/ipextexturefilter.html#1

3/8

3/18/13

Image Processing Toolbox - Texture Segmentation Using Texture Filters Demo - MathWorks India

Get raw image of the top texture using r o u g h M a s k .

I 2=I ; I 2 ( r o u g h M a s k )=0 ; i m s h o w ( I 2 ) ;

Use e n t r o p y f i l tto calculate the texture image.

E 2=e n t r o p y f i l t ( I 2 ) ; E 2 i m=m a t 2 g r a y ( E 2 ) ; i m s h o w ( E 2 i m ) ;

www.mathworks.in/products/image/examples.html?file=/products/demos/shipping/images/ipextexturefilter.html#1

4/8

3/18/13

Image Processing Toolbox - Texture Segmentation Using Texture Filters Demo - MathWorks India

Threshold E 2 i musing g r a y t h r e s h .

B W 2=i m 2 b w ( E 2 i m , g r a y t h r e s h ( E 2 i m ) ) ;

i m s h o w ( B W 2 ) f i g u r e ,i m s h o w ( I ) ;

If you compare B W 2to I , you notice there are two objects segmented in B W 2 . Use b w a r e a o p e nto get a mask for the top texture.

www.mathworks.in/products/image/examples.html?file=/products/demos/shipping/images/ipextexturefilter.html#1

5/8

3/18/13

Image Processing Toolbox - Texture Segmentation Using Texture Filters Demo - MathWorks India
m a s k 2=b w a r e a o p e n ( B W 2 , 1 0 0 0 ) ; i m s h o w ( m a s k 2 ) ;

Step 5: Display Segmentation Results


Use m a s k 2to extract the top and bottom texture from I .

t e x t u r e 1=I ; t e x t u r e 1 ( ~ m a s k 2 )=0 ; t e x t u r e 2=I ; t e x t u r e 2 ( m a s k 2 )=0 ;

i m s h o w ( t e x t u r e 1 ) ; f i g u r e ,i m s h o w ( t e x t u r e 2 ) ;

www.mathworks.in/products/image/examples.html?file=/products/demos/shipping/images/ipextexturefilter.html#1

6/8

3/18/13

Image Processing Toolbox - Texture Segmentation Using Texture Filters Demo - MathWorks India

Outline the boundary between the two textures.

b o u n d a r y=b w p e r i m ( m a s k 2 ) ; s e g m e n t R e s u l t s=I ; s e g m e n t R e s u l t s ( b o u n d a r y )=2 5 5 ; i m s h o w ( s e g m e n t R e s u l t s ) ;

Using Other Texture Filters in Segmentation


Instead of e n t r o p y f i l t , you can use s t d f i l tand r a n g e f i l twith other morphological functions to achieve similar segmentation results.

S=s t d f i l t ( I , n h o o d ) ; i m s h o w ( m a t 2 g r a y ( S ) ) ;

www.mathworks.in/products/image/examples.html?file=/products/demos/shipping/images/ipextexturefilter.html#1

7/8

3/18/13

Image Processing Toolbox - Texture Segmentation Using Texture Filters Demo - MathWorks India

R=r a n g e f i l t ( I , o n e s ( 5 ) ) ; i m s h o w ( R ) ;

1994-2013 The MathWorks, Inc.

Site Help

Patents

Trademarks

Privacy Policy

Preventing Piracy Join the conversation

www.mathworks.in/products/image/examples.html?file=/products/demos/shipping/images/ipextexturefilter.html#1

8/8

Anda mungkin juga menyukai