Image pre-processing and segmentation
Are my methods correct?


That depends on what you want to accomplish. Since you are "learning python and image processing with python", it seems you picked some related methods to explore, which is good. But since your project is called "Classification of breast cancer images with deep learning", and you're not using deep learning, maybe you didn't pick the right methods...

See below for some more concepts.


  Are the outputs correct? Do I find the right areas?


Again, that depends on what your goal is. Do you know what these images represent? If no, then you need to start there. Understand what the image represents, what is relevant in it, and understand what the output of your algorithms will be used for. Then you will be able to answer your question yourself.

It looks like you found mostly the nuclei, the results are quite OK if that is what you're after.


  Did I use the K-Means algorithm correctly?


You've copy-pasted this from the OpenCV tutorial, so it's correct. But it also is a bit redundant, since the values of center are not useful to you in this case. The output label is an image with values 0 and 1, representing background and foreground. You should be able to directly display that (maybe multiply by 255 first).

Also the line where you convert BGR to RGB is redundant, the k-means result will be the same regardless, and you don't need the colors after that.



When dealing with brightfield microscopy, as you are, you might want to consider separating the stains instead of directly using the RGB values. These images are all H&amp;E stain (Hematoxylin and Eosin). These are purple and pink, respectively. Because we're dealing with transmitted light, and the dyes absorb light of specific wavelengths, we see darker pixels of specific colors. The absorption is characterized by the Beer-Lambert law. This law states that the amount of light transmitted (and thus seen by the camera) is given by \$10^{-A}\$, with \$A\$ proportional to the amount of dye. Thus, given a pixel value \$v\$ and the illumination intensity \$v_\text{max}\$ (the whitest area in the image), you can compute \$-log(v/v_\text{max})\$, which is proportional to the amount of dye. You can do this separately for each of the channels R, G and B. Each dye has a different absorption coefficient for each channel. If you know these (you can compute them from the image data), you can now do a linear unmixing (solve a linear set of equations) to derive, for each pixel, the relative amount of Hematoxylin and the relative amount of Eosin at that location on the slide. These two values is what you should be working with.