how can i control cluster
Afficher commentaires plus anciens
when i segment a color image its divided into three clusters i need one cluster of then which is of my interest, but every time the cluster changes i.e for each iteration and i get different cluster, simply i want to get fix cluster number not variable.
thanks in advance

16 commentaires
Walter Roberson
le 17 Fév 2017
Please delete your code out of the tags and add it to your question.
Image Analyst
le 18 Fév 2017
Attach your image. It's hard to discuss image processing without an image, don't you agree? In many cases kmeans is not appropriate for doing color classification - you can probably easily think up such cases. I have a kmeans color classification routine/demo if you want proof.
Niaz Ahmad
le 28 Fév 2017
Niaz Ahmad
le 28 Fév 2017
Walter Roberson
le 28 Fév 2017
You see that yellowing? You also get that kind of yellowing when there is iron deficiency, which is not a disease. You also get leaf yellowing when the plant is being over-watered. You also get leaf yellowing when the plant is being under-watered.
You also get leaf yellowing when there is fungal rot of the roots; some definitions of "disease" exclude that.
You see that brown spot? You also get that brown spots not so different from that from some kinds of caterpillar or wasp damage, which is not a disease.
Now, it might be the case that those kinds of plants, in that area, are all watered properly, and do not get attacked by caterpillars or wasps. But that would be something contextual rather than absolute: in other cases, the yellowing or brown spot would have to be discounted as irrelevant.
Therefore there are no absolute features applicable to all leaf disease situations that can be applied. You need to come up with something relevant to your situation.
Image Analyst
le 28 Fév 2017
And what would k be for that image? 2? 4? More? What if the background were all "green" instead of dirt? Do you expect to have to determine k for each individual image?
Niaz Ahmad
le 1 Mar 2017
Niaz Ahmad
le 1 Mar 2017
Image Analyst
le 1 Mar 2017
Just invert the mask that you used to blacken the image.
background = ~mask;
Niaz Ahmad
le 1 Mar 2017
Walter Roberson
le 1 Mar 2017
We already talked about that below. You cannot control which cluster number will be assigned to which meaning. kmeans does not know anything about what the clusters mean.
Niaz Ahmad
le 1 Mar 2017
Walter Roberson
le 1 Mar 2017
No, the conclusion should be that you need to use techniques to match between cluster numbers and meaning. For example it might be the case that average rbg for the cluster allows you to determine which cluster you are dealing with.
Image Analyst
le 1 Mar 2017
Modifié(e) : Image Analyst
le 1 Mar 2017
I agree with Niaz. As I've said before, kmeans is a crummy method to do clustering and classification on plant images in general (because you'll never know how many clusters there might be), though it might work fine on one particular image if you know certain things in advance (like number of clusters).
You might look into Microsoft's research on flower-finder: https://www.microsoft.com/en-us/research/blog/researchers-team-up-with-chinese-botanists-on-machine-learning-flower-recognition-project/
You could do a similar thing but with different leaf diseases.
Niaz Ahmad
le 2 Mar 2017
Niaz Ahmad
le 3 Mar 2017
Réponses (1)
Walter Roberson
le 17 Fév 2017
0 votes
You cannot control which cluster number a particular point is assigned to if you are using the kmeans algorithm.
kmeans uses random initialization of centroids, so any point could end up randomly near any centroid.
The Mathwork's kmeans does have a parameter to allow you to pass in initial centroids instead of using random centroids. However, the kmeans algorithm actively moves points between centroids, so the centroids "move around" and can effectively swap identities.
If you have prior knowledge of the "right" cluster number for points in two different centroids, then you can relabel the index numbers.
Always remember, though: kmeans does not have any idea what the data means, so there is no way it can be told that "cancer state III must be assigned cluster #2" for example.
13 commentaires
Niaz Ahmad
le 17 Fév 2017
Walter Roberson
le 17 Fév 2017
Suppose you cluster and you get back a variable named
clusteridx
Then start with
newidx = 0 * clusteridx;
Now if you have a point (r1, c1) that you know belongs to the cluster you want to be labeled as 1, and you have a point (r2, c2) that you know belongs to the cluster you want labeled as 2, then:
idx1 = clusteridx(r1, c1);
mask1 = clusteridx == idx1;
newidx( mask1 ) = 1;
idx2 = clusteridx(r2, c2);
mask2 = clusteridx == idx2;
newidx( mask2 ) = 2;
mask3 = clusteridx ~= 0 & ~mask1 & ~mask2;
newidx( mask3 ) = 3;
The problem is that in general you do not know ahead of time which point is going to belong to which cluster.
Do you know something ahead of time about the locations you want to label as 1? For example, do you know that it will be the brightest cluster, and that cluster 3 will be the darkest cluster? Or do you know that the cluster to be labeled as 1 is the red-est cluster?
With that kind of information known in advance, you could use regionprops() on the labeled image that is clusteridx and examine the properties to figure out which cluster index corresponds to which meaning, after which you can relabel.
Niaz Ahmad
le 17 Fév 2017
Walter Roberson
le 17 Fév 2017
"can we do color segmentation for leaf related diseases without using clustering???"
Yes. Use http://scholar.google.com to research color image segmentation methods; there are about 1 million articles to go through, so it is highly likely that somewhere in that haystack there is a method that does not use clustering.
Niaz Ahmad
le 18 Fév 2017
Walter Roberson
le 18 Fév 2017
newidx = idx;
newidx(newidx == 2) = 1; %merge class 2 with class 1
Niaz Ahmad
le 19 Fév 2017
Walter Roberson
le 19 Fév 2017
http://scholar.google.com shows at least 60 papers on that topic. I will leave it to you to read them and figure out which ones are best for you.
Niaz Ahmad
le 27 Fév 2017
Walter Roberson
le 27 Fév 2017
I don't know. What were the conclusions in
and
Niaz Ahmad
le 28 Fév 2017
Image Analyst
le 28 Fév 2017
I guess you didn't see my comment. How can you expect to get good answers on image processing without even providing an image? I'm surprised Walter even went this far with you.
Walter Roberson
le 28 Fév 2017
"which algorithm will be best for extracting more features"
Which-ever one works best for your data.
No-one knows what the best set of features or best algorithm is for your situation. There is no known useful mathematical model of what diseased leaves look like compared to healthy leaves for the diseases of interest to you for the types of plants of interest to you for the growing conditions of interest to you and photographed with the technologies and lighting conditions of interest to you -- but we would need such a mathematical model in order to predict what the best features and algorithm was.
The literature is full of papers along the lines of "We had a variety of plants and growing conditions and diseases of interest to us, and we experimented with a few different algorithms, and this is what happened; maybe this would work okay for you too." But none of those are your situation -- not unless you are copying their data and seeing what you can come up with.
Catégories
En savoir plus sur Agriculture dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


