Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1 hiepltsdsgthh
552
Sign out
home
articles
quick answers
discussions
features
community
help
Next
Article Browse Code Stats Revisions (6) Alternatives Comments & Discussions (22)
About Article
This code performs a fuzzy C-means clustering and segmentation of color images, and can be used for feature extraction. Type Article GPL3 5 Jul 2010 39,419 3,868 58 times
Is your email address OK? You are signed up for our newsletters but your email address is either unconfirmed, or has not been reconfirmed in a long time. Please click here to have a confirmation email sent so we can confirm your email address and start sending you newsletters again. Alternatively, you can update your subscriptions.
Introduction
Image segmentation, the partitioning of an image into homogeneous regions based on a set of characteristics, is a key element in image analysis and computer vision. Clustering is one of the methods available for this purpose. Clustering is a process which can be used for classifying pixels based on similarity according to the pixel's color or gray-level intensity. The K-means algorithm has been used for a fast and crisp "hard" segmentation. The Fuzzy Set theory has improved this process by allowing the concept of partial membership, in which an image pixel can belong to multiple clusters. This "soft" clustering allows for a more precise computation of the cluster membership, and has been used successfully for image clustering and for the unsupervised segmentation of medical, geological, and satellite images.
Algorithm
The fuzzy C-means (FCM) algorithm follows the same principles as the K-means algorithm in that it compares the RGB value of every pixel with the value of the cluster center. The main difference is that instead of making a hard decision about which cluster the pixel should belong to, it assigns a value between 0 and 1 describing "how much this pixel belongs to that cluster" for each cluster. Fuzzy rule states that the sum of the membership value of a pixel to all clusters must be 1. The higher the membership value, the more likely that pixel is to belong to that cluster. The FCM clustering is obtained by minimizing an objective function shown in equation (1): (1) Where: J is the objective function
J is the objective function n is the number of pixels in the image E c is the number of clusters is the fuzzy membership value from table m is a fuzziness factor (a value > 1) pi is the ith pixel in E vk is the centroid of the kth cluster |pi vk| is the Euclidean distance between pi and vk defined by equation (2):
Top News
(2) The calculation of the centroid of the kth cluster is achieved using equation (3): 10 Pieces of Really Bad Advice (for Computer Scientists)
Get the Insider News free each morning.
(3) The fuzzy membership table is calculated using the original equation (4):
Related Videos
(4) This algorithm has been extended for clustering of color images in the RGB color space. Hence, the computation given in equation (2) to compute the Euclidean distance between the values pi and vk is modified to incorporate RGB colors, and is shown in equation (5):
Welcome to CodeProject.TV
(5)
Pseudo-Code
As mentioned earlier, this is an iterative process. The pseudo-code is as follows: Step 1: Set the number of clusters, the fuzzy parameter (a constant > 1), and the stopping condition Step 2: Initialize the fuzzy partition matrix Step 3: Set the loop counter k = 0 Step 4: Calculate the cluster centroids, calculate the objective value J Step 5: For each pixel, for each cluster, compute the membership values in the matrix Step 6: If the value of J between consecutive iterations is less than the stopping condition, then stop; otherwise, set k=k+1 and go to step 4 Step 7: Defuzzification and segmentation
Related Articles
Matrix Multiplication in C# Creating animations with Dundas Chart for ASP.NET Smarter Data Labels with Dundas Chart SmartLabels Understanding Chart Areas with Dundas Chart for .NET Add "Select All" to parameter lists in SQL Reporting Using screensavers inside the Windows Media Player Making Sense of Geographic Data with Dundas Map and AJAX Handling connection notification between a desktop machine and Windows CE based devices SmartLink Create data-driven applications with the Hera Application Framework Towards the self-documenting database: extended properties Accessibility audit vs. accessibility testing Digital Signatures and PDF Documents Color Scale Filter WMP Power Hour APP Merge Landscape and Portrait PDFs using ASP.NET How to conduct an SMS survey using a cell phone connected SMS gateway and MS Access
Using Barcodes in Documents Best Practices How to Retrieve EMC Centera Cluster/Pool Capabilities "Hey! Is That My Car? How to Sharpen a QuickBird Satellite Image Using DotImage" Integrate your SharePoint environment into the open standards-based WebSphere Portal platform using the Visual Studio IDE
Clicking the "Fuzzy C-means Clustering" button will start the computation. The program will start by creating a C l u s t e r P o i n tobject for every pixel in the image:
Collapse | Copy Code
L i s t < C l u s t e r P o i n t >p o i n t s=n e wL i s t < C l u s t e r P o i n t > ( ) ; f o r( i n tr o w=0 ;r o w<o r i g i n a l I m a g e . W i d t h ;+ + r o w ) { f o r( i n tc o l=0 ;c o l<o r i g i n a l I m a g e . H e i g h t ;+ + c o l ) { C o l o rc 2=o r i g i n a l I m a g e . G e t P i x e l ( r o w ,c o l ) ; p o i n t s . A d d ( n e wC l u s t e r P o i n t ( r o w ,c o l ,c 2 ) ) ; } }
L i s t < C l u s t e r C e n t r o i d >c e n t r o i d s=n e wL i s t < C l u s t e r C e n t r o i d > ( ) ; / / C r e a t er a n d o mp o i n t st ou s eat h ec l u s t e rc e n t r o i d s R a n d o mr a n d o m=n e wR a n d o m ( ) ; f o r( i n ti=0 ;i<n u m C l u s t e r s ;i + + ) { i n tr a n d o m N u m b e r 1=r a n d o m . N e x t ( s o u r c e I m a g e . W i d t h ) ; i n tr a n d o m N u m b e r 2=r a n d o m . N e x t ( s o u r c e I m a g e . H e i g h t ) ; c e n t r o i d s . A d d ( n e wC l u s t e r C e n t r o i d ( r a n d o m N u m b e r 1 ,r a n d o m N u m b e r 2 , f i l t e r e d I m a g e . G e t P i x e l ( r a n d o m N u m b e r 1 ,r a n d o m N u m b e r 2 ) ) ) ; }
The cluster centers (or centroids) are selected randomly for the first pass, and will be adjusted by the algorithm. Finally, create the F C Mobject and start the iterations:
Collapse | Copy Code
F C Ma l g=n e wF C M ( p o i n t s ,c e n t r o i d s ,2 ,f i l t e r e d I m a g e ,( i n t ) n u m e r i c U p D o w n 2 . V a l u e ) ; k + + ; a l g . J=a l g . C a l c u l a t e O b j e c t i v e F u n c t i o n ( ) ; a l g . C a l c u l a t e C l u s t e r C e n t r o i d s ( ) ; a l g . S t e p ( ) ; d o u b l eJ n e w=a l g . C a l c u l a t e O b j e c t i v e F u n c t i o n ( ) ; C o n s o l e . W r i t e L i n e ( " R u nm e t h o di = { 0 }a c c u r a c y={ 1 }d e l t a = { 2 } " , k ,a l g . J ,M a t h . A b s ( a l g . J-J n e w ) ) ; b a c k g r o u n d W o r k e r . R e p o r t P r o g r e s s ( ( 1 0 0*k )/m a x I t e r a t i o n s ," I t e r a t i o n"+k ) ; i f( M a t h . A b s ( a l g . J-J n e w )<a c c u r a c y )b r e a k ;
Once the iterations are done, the algorithm will perform a defuzzification process to assign the pixel to the cluster for which it has the highest membership value. For each cluster, the program will then save a segmented image containing the pixels from the original image that are contained in that cluster. As an example, the clustering of the following test image with 2 clusters:
By using the cluster information and the pixels from the original image, the following regions can be extracted:
Because this algorithm is very computationally intensive, it has a tendency to "lock" the GUI and not refresh the status and the working image. For that reason, I had to use a worker thread.
Points of Interest
This is my first post, and my first C# program, so I am sure that it leaves a lot of room for improvement. But overall, I hope that you will find this project fun and interesting!
References
Java Image Processing Cookbook, the Fuzzy C-means algorithm by Rafael Santos. Modified Fuzzy C-means Clustering Algorithm with Spatial Distance to Cluster Center of Gravity, 2010 IEEE International Symposium on Multimedia, Taichung, Taiwan, December 13-December 15 2010.
License
This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)
Graduate student Department of Computer and Information Science Gannon University, Erie, PA
Article Top
Like
10
Tw eet
Rate this:
Poor
Excellent
Vote
Search this forum Noise Very Low Layout Normal Per page 25
Go Update
Eps? fuzzy c means 5 all the way My vote of 5 My vote of 4 Can I suggest one of my articles? Re: Can I suggest one of my articles? My vote of 1 Re: My vote of 1 Re: My vote of 1 Maybe a small problem Re: Maybe a small problem My vote of 5 So cool! I like this a lot Great start Few tips for you..... Re: Few tips for you..... Re: Few tips for you..... My vote of 1 Re: My vote of 1 Needs improvement...
Last Visit: 31 Dec '99 - 23:00 Last Update: 27 Apr '13 - 18:36
imparente arc_157 khairul786 khairul786 gorgias99 Paulo Zemek Member 1773855 ghh125 Nicolas Dorier sanosay likuan Christophe Gauge Joel Ivory Johnson hackcat Yves Alphons van der Heijden Md. Marufuzzaman gaugec Md. Marufuzzaman gaurav_verma_mca Laserson Sandeep Mewara
24 Apr '13 - 6:09 21 Mar '13 - 0:28 12 Jan '12 - 9:40 12 Jan '12 - 9:39 15 Mar '11 - 5:54 9 Mar '11 - 13:40 12 Apr '11 - 17:39 12 Dec '10 - 5:26 10 Mar '11 - 2:51 4 Apr '12 - 17:43 27 Oct '10 - 2:51 2 Feb '11 - 13:40 19 Jul '10 - 9:38 19 Jul '10 - 8:23 12 Jul '10 - 18:57 10 Jul '10 - 17:54 5 Jul '10 - 0:14 5 Jul '10 - 10:58 5 Jul '10 - 11:31 4 Jul '10 - 23:25 12 Mar '11 - 14:45 4 Jul '10 - 23:18 Refresh 1
Last Update: 27 Apr '13 - 18:36 Suggestion Question Bug Answer Joke Rant Admin
Refresh
Permalink | Advertise | Privacy | Mobile Web03 | 2.6.130426.1 | Last Updated 9 Mar 2011
Article Copyright 2010 by Christophe Gauge Everything else Copyright CodeProject, 1999-2013 Terms of Use