Damn, this saved my research project. Thank you so much for the simple explanation, most k-means videos on youtube don't use images directly and that was killing me until I found your video. Thanks so much for the awesome content, you've helped me a lot today!!
man, I've literally been spending hours trying to figure out how to do this, and you easily and simply knocked this out for me in no time. Not only that, it was done in a way that makes sense and was easy to follow. I've never used cv2 before and had to install everything, but this was incredibly useful. Liked and favorited. Keep up the good work
Third arguement is criteria in the syntax, why is it 'None' here, and criteria is only 4th even in sample code given in official website (openCV). What does None specify?
Could I get size information directly from segmented image gotten by k means clustering method? I think it is difficult to get clear contour line in case of noisy grain (mixed labels in grain)
Hi. How to use 5 dimensions feature space with kmeans. For instance r,g,b,x,y. To add more features is simple - just add one column per feature to array. But how to reconstruct image back after segmentation?
If you mean displaying image pixels in color then just use any colormap that you like. Or you can use the process from video 23 where I assigned specific pixel value to each segmented region. If you are referring to plotting clusters where data points are different colors, you can watch my video from my work account: ua-cam.com/video/H_L7V_BH9pc/v-deo.html
Sir, how to similarity animal photographs segregation move to folderwise. Example Tiger, elephant, deer, buffalo, wild pig, etc. Can you possible. please help
Thanks a lot for the video, I have a technical question: what is exactly center[label.flatten()] in line 26 doing? How can this synthax return a 751000 x 3 array? Thanks, it's probably some interpretation of the numpy arrays manipulation that I'm missing.
I was trying to understand this too on my code. I was expecting that center = center of each cluster. But it's actually the "mean value" of color in the original image at that cluster area. So, the values you have at center variable are the colors of the clusters. for example: (255, 255, 255) if its a white cluster. If you have 4 clusters, you gonna have 4 colours on this list. Indexes: 0, 1, 2, 3 The label is a variable that has the same shape of img2. But it only carries the information of which cluster each pixel is linked. So if you have 4 clusters, on a 10x1 (1 channel image), array, it might look like this: label = [0,0,1,3,2,3,3,3,2,1] When he uses center[label.flaten()] he applies the label values as a index to choose the right color of the cluster on each position. And saves the result of this on "res" list.
Depends on how images look, if you can manually classify them then there is a good chance they can be automatically classified using image processing. We do this all the time in many fields, for example classifying the type of nuclei in biology or classification of mineralogy based on texture in geology. Deep learning may be required.
I have two labelled classes, I need for each class to be segmented into 2 subclasses using the KMeans. so class 1 would be class1_1 and class1_2 and so on. Thanks in advance.
Can we perform classification on segmented images? I mean, can we feed the segmented images to the svm classifier? If yes, then from the segmented images, how will the svm or any classifier, classify the images?
Yes you can use segmented images as input to another machine learning pipeline. If your classification is based on number of pixels corresponding to a given class then it makes sense. But if you want to classify images as cats/dogs or nucleus/mitochondria or other application, then it makes sense to work directly with raw images. This is because original raw images will have many features that are important for classification.
@@DigitalSreeni Thank you so much! Can I get your email id, so that I can reach out to you for the doubts I have regarding the project that I'm working on?
Since you're working on RGB image, you reshaped it to (-1, 3) because the 3 represents r, b, g channels. But for grey scale images how should I reshape it? Can you please answer this?
Passing -1 for reshaping numpy array means that we do not know what that number is going to be. In this case I want to collapse my data into some (unknown, 3), so I passed -1. In your case, if you only have 1 channel and want the output to be (unknown, 1) then pass (-1,1). If you just want to convert to single vector, then just flatten - np.flatten(array).
Thanks for this interesting video. I was working on some outlier detection problem where DBSCAN gives pretty good result. Any way to do segmentation using DBSCAN clustering in python which could consume reasonable RAM space. The DBSCAN on images explode the memory requirements and hard to implement using sklearn. Any other way ?
I hope you're referring to DBSCAN module from sklearn. DBSCAN is fine for non-image data but can be computationally expensive for images. Any limitations by k-means can be addressed using Gaussian mixture model (GMM). I am not sure how results GMM compares against DBSCAN but computationally it is much faster.
Sure, you can use this approach to generate data for deep learning but if k-means can solve your segmentation problem why would you need deep learning? I recommend using the simplest approach that solves the problem.
Hi sir. first I want to thank you for making this tremendously helpful videos. I have one question regarding this video's topic. what is the best way to find the optimal K?
just copy it, only a few lines but some of it was from here opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_ml/py_kmeans/py_kmeans_opencv/py_kmeans_opencv.html
Damn, this saved my research project. Thank you so much for the simple explanation, most k-means videos on youtube don't use images directly and that was killing me until I found your video. Thanks so much for the awesome content, you've helped me a lot today!!
You're welcome.
man, I've literally been spending hours trying to figure out how to do this, and you easily and simply knocked this out for me in no time. Not only that, it was done in a way that makes sense and was easy to follow. I've never used cv2 before and had to install everything, but this was incredibly useful. Liked and favorited. Keep up the good work
Thanks. I am glad you found my channel. Now time to tell your friends about it :)
Thank you for all amazing tutorials. Here I request to give tutorials on active contour models
Third arguement is criteria in the syntax, why is it 'None' here, and criteria is only 4th even in sample code given in official website (openCV). What does None specify?
Could I get size information directly from segmented image gotten by k means clustering method? I think it is difficult to get clear contour line in case of noisy grain (mixed labels in grain)
Amazing tutorial! Thank you sir.
Hi. How to use 5 dimensions feature space with kmeans. For instance r,g,b,x,y. To add more features is simple - just add one column per feature to array. But how to reconstruct image back after segmentation?
Very clear and useful video to get me started on segmentation. Cheers!!
Great to hear!
amazing tutorial! is there any way to display the clusters in color?
If you mean displaying image pixels in color then just use any colormap that you like. Or you can use the process from video 23 where I assigned specific pixel value to each segmented region.
If you are referring to plotting clusters where data points are different colors, you can watch my video from my work account: ua-cam.com/video/H_L7V_BH9pc/v-deo.html
☕.thanks Sreeni Sir. yiu gave a Channel to Motivate Students Towards HEALTH AND SCIENCE
Thank you very much.
@@DigitalSreeni very very welcome Sir,
Sir, how to similarity animal photographs segregation move to folderwise. Example Tiger, elephant, deer, buffalo, wild pig, etc. Can you possible. please help
Thanks a lot for the video, I have a technical question: what is exactly center[label.flatten()] in line 26 doing?
How can this synthax return a 751000 x 3 array?
Thanks, it's probably some interpretation of the numpy arrays manipulation that I'm missing.
I was trying to understand this too on my code. I was expecting that center = center of each cluster. But it's actually the "mean value" of color in the original image at that cluster area.
So, the values you have at center variable are the colors of the clusters. for example: (255, 255, 255) if its a white cluster. If you have 4 clusters, you gonna have 4 colours on this list. Indexes: 0, 1, 2, 3
The label is a variable that has the same shape of img2. But it only carries the information of which cluster each pixel is linked.
So if you have 4 clusters, on a 10x1 (1 channel image), array, it might look like this:
label = [0,0,1,3,2,3,3,3,2,1]
When he uses center[label.flaten()] he applies the label values as a index to choose the right color of the cluster on each position. And saves the result of this on "res" list.
explained in detail, thank you so much!!
How effective is the image segmentation method for determining if a pv panel is dirty and classifying the type of soiling?
Depends on how images look, if you can manually classify them then there is a good chance they can be automatically classified using image processing. We do this all the time in many fields, for example classifying the type of nuclei in biology or classification of mineralogy based on texture in geology. Deep learning may be required.
@@DigitalSreeni Yes, sir. They can be manually classified. Thank you for the reply.
Can we segment malaria blood smear images using this method
I am not aware of how these images would look like. Give it a try and check it out.
Wow! Thank you so much for explaining patiently :-)
You're very welcome!
I have two labelled classes, I need for each class to be segmented into 2 subclasses using the KMeans. so class 1 would be class1_1 and class1_2 and so on. Thanks in advance.
Can we perform classification on segmented images? I mean, can we feed the segmented images to the svm classifier? If yes, then from the segmented images, how will the svm or any classifier, classify the images?
Yes you can use segmented images as input to another machine learning pipeline. If your classification is based on number of pixels corresponding to a given class then it makes sense. But if you want to classify images as cats/dogs or nucleus/mitochondria or other application, then it makes sense to work directly with raw images. This is because original raw images will have many features that are important for classification.
@@DigitalSreeni Thank you so much! Can I get your email id, so that I can reach out to you for the doubts I have regarding the project that I'm working on?
Since you're working on RGB image, you reshaped it to (-1, 3) because the 3 represents r, b, g channels. But for grey scale images how should I reshape it? Can you please answer this?
Passing -1 for reshaping numpy array means that we do not know what that number is going to be. In this case I want to collapse my data into some (unknown, 3), so I passed -1. In your case, if you only have 1 channel and want the output to be (unknown, 1) then pass (-1,1). If you just want to convert to single vector, then just flatten - np.flatten(array).
@@DigitalSreeni Understood. Thank you so much. And your videos are helping me so so much for my project. Thank you!!
Sir where did we get that document,can u post it in description or else in comment box please sir
Which document? If you are referring to the image then I just got it from Google search: deben.co.uk/wp-content/uploads/2012/07/BS-Image-lrg.jpg
Not this that code present document
Hello, is it possible to create contours/masks from the created clusters ?
Well, you can treat the segmented images as masks.
@@DigitalSreeni Thank you very much for the reply!
where can i find the image used
deben.co.uk/wp-content/uploads/2012/07/BS-Image-lrg.jpg
Having trouble,it shows error AttributeError: Nonetype object has no attribute 'reshape'
Nonetype object means there is no data (image). Please make sure the image is properly read, check the path, etc.
Thanks for this interesting video. I was working on some outlier detection problem where DBSCAN gives pretty good result. Any way to do segmentation using DBSCAN clustering in python which could consume reasonable RAM space. The DBSCAN on images explode the memory requirements and hard to implement using sklearn. Any other way ?
I hope you're referring to DBSCAN module from sklearn. DBSCAN is fine for non-image data but can be computationally expensive for images. Any limitations by k-means can be addressed using Gaussian mixture model (GMM). I am not sure how results GMM compares against DBSCAN but computationally it is much faster.
@@DigitalSreeni Thanks for the advice. I will try GMM as well.
sir please add video on fuzzy k-mean clustering image segmentation
Is it a good way to generate segmentation dataset for cnn? Thank you
Sure, you can use this approach to generate data for deep learning but if k-means can solve your segmentation problem why would you need deep learning? I recommend using the simplest approach that solves the problem.
Hi! your video is helpful. Do you have a program for SLIC Algorithms using Python :( I am researching its but it is too hard :( Help me
I love your channel very helpfull, thank you!
You're very welcome!
can i use Kmeans for a image with only one band ?
Yes, you can use k means for single channel images, example grayscale images.
What is image j
How can I do it?
Thanks a lot
Thank you again! Sir you help me alot again!!
Please sir, can I apply this segmentation to ''.tif '' image ?
Yes, of course. Just read them using scikit-image or tifffile. The rest of the process should be the same.
@@DigitalSreeni Thank you very much sir for your reply. I want to apply it for multitemporal Sentinel 2 satellite imagery.
Kindly use clear images like cat and dog or any thing which can show clear segmentation
canu prepare a video for otsus binarization ?
I’ve got 2 videos on otsu, please check other videos on my channel.
Note: This will not work with the latest python version. Python 3.6 is ok for me. Thanks!
I just tested it on python3.7 and it works fine. May be you have other issues with your environment?
Hi sir. first I want to thank you for making this tremendously helpful videos. I have one question regarding this video's topic. what is the best way to find the optimal K?
Please watch my video number 53 that explains the process of picking the right number of parameters for unsupervised segmentation, including k-means.
@@DigitalSreeni Thank you very much for the response.
I have one more question.. what method/package do you recommend for k means clustering a 3d matrix?
where can i get the whole code ?
just copy it, only a few lines
but some of it was from here
opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_ml/py_kmeans/py_kmeans_opencv/py_kmeans_opencv.html
What’s the software used is it python or matlab?
Python
He is using Spyder with Python version 3.7.
It's Pokemon go
Would actually been have helpful to implement the algorithm by hand, it's not that hard and what's in this video is anyways in the CV docs
Sir, ap kamal hn
dope
te amo