Notes de Rachel/Interns, Summer 2018 (51 notes)/Image Recognition

From Hackuarium
Revision as of 09:41, 26 November 2026 by Zaphod (talk | contribs) (Adding Category:Note (batch edit via API))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Notes de Rachel / Interns, Summer 2018 (51 notes)

Database: https://drive.google.com/drive/u/1/folders/1yRfCqFYzeVxBZXJRt0VQ9y3SvHFf_c_Z



For OpenCV installation: https://www.pyimagesearch.com/2016/12/19/install-opencv-3-on-macos-with-homebrew-the-easy-way/ (completed on 26.07.18)

First OpenCV tutorial: https://docs.opencv.org/master/dc/d2e/tutorial_py_image_display.html

Some ideas of methods proposed on the forums :

  1. Finding contours of the filtered image. (does not work well with cells that are close together)
  2. Gaussian blur and find local maxima on the image. (same problem as 1)
  3. Canny Edge detection (output result detect non cells segment)

Steps for the detection:
Methodology used is inspired by this one: https://www.unige.ch/medecine/bioimaging/files/3714/1208/5964/CellCounting.pdf



30.07.18
Problem with the cell detection 
The images taken last week from the slides of the workshop show blue-coloured cell. 

Rachel-436282a9b6bffd20-Screen-Shot-2018-07-26-at-16.28.09.png

Thanks to the clear difference of colour between the inner and outer cell, the contour of the cell was quite easy to find.

Rachel-907ebbf28a539fe7-Screen-Shot-2018-07-30-at-14.39.25.png

When we did the experiment again (last Friday), we obtain much translucent cells. Only the nucleus of the cell is coloured in blue. This is the expected result as methyl blue colours the DNA. Nevertheless with this kind of pictures, the algorithm did not work anymore...

Rachel-c71455d30c33f46a-WhatsApp-Image-2018-07-30-at-14.30.07.jpeg
Rachel-be653be7dc4be3fa-Screen-Shot-2018-07-30-at-14.46.13.png

31.07.18
Solution: 
Do some pre-processing, changing the brightness,…
http://answers.opencv.org/question/26280/background-color-similar-to-object-color-how-isolate-it/ (C++)
In python: https://stackoverflow.com/questions/51120831/opencv-trackbar-assertion-failed-error

The “tuna-algorithm” was implemented but the bigger contour is not necessary the cell. 
Mainly the contour which is selected correspond to a shadow in the image. 



02.08.18
Idea 1: remove background image to reduce the shadow

Rachel-518650085c349532-10-12-46.jpg

The subtraction reduces the shadows:

Idea 2: compute roundness in order to select the cell. In addition a filter can be done according the size of the round.

With those additional implementations, the algorithm is capable to correctly detect the cell. (Tested only in one example)

Rachel-8eaac9b4ced45685-Screen-Shot-2018-08-02-at-17.24.27.png
Rachel-b39e91ad8d6c0513-Screen-Shot-2018-08-03-at-09.38.59.png

03.08.18
The parameters were changed in order to correctly detect the cells in the two images. Nevertheless more images analysis to ensure the correctness of the algorithm would be interesting !



Note: It seems better to take a print screen of the whole instead of only on the cell. This ensure the deletion of some shadows, nevertheless there is still some horizontal lines which could corresponds to the renewal of the image with the camera. 
Solution: white balance !



06.08.18
Detection of the nucleus
Idea: detect blue
Then combine with the previous contour detected => if contour + blue inside, then cell
https://www.pyimagesearch.com/2014/08/04/opencv-python-color-detection/
https://handmap.github.io/colour-detection-using-rgb-boundaries/
https://github.com/HandMap/boundedRGB/blob/master/src/RGBcontrol.py

07.08.18
The blue colour detection is not easily done as the blue of the nucleus is the same as the colour of the background in the shadow. 
It could be good to try the blue colour detection inside the mask define by the previous algorithm as being the cell. This process would confirme that the detected mask are effectively cells.

A new way to remove the background was tested. Following is the differences resulting by the algorithm:
https://www.pyimagesearch.com/2017/06/19/image-difference-with-opencv-and-python/

08.08.18
Need to merge this detection process with the previous mask algorithm:

  1. Find contour of the image
  2. Threshold to select the contour of the cell only, according to size
  3. To ensure the detection of the cell, try the blue detection process inside the cell to find the nucleus

09.08.18
Step 2:

Rachel-83da16339dccfb7f-Screen-Shot-2018-08-09-at-10.17.41.png

Next, apply a mask in order to keep only an image with what is inside the contour from step 2. Then the blue-detection check would be applied inside this image.

Rachel-70224978e4d332d0-Screen-Shot-2018-08-09-at-14.22.29.png
Rachel-5bd260e4255f5199-Screen-Shot-2018-08-09-at-14.22.40.png

Step 3: Detection of the nucleus, meaning detection of the blue colour inside the image
This is going to be a complicated thing because the blue is really poorly defined in the image.

Idea: Not detecting blue but instead, detect nearly round structures inside the cell that have +/- the size of a typical nucleus. => good if finally we don’t use methyl blue but another colorant.

Idea: maybe reduce the number of colour inside the image: https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_ml/py_kmeans/py_kmeans_opencv/py_kmeans_opencv.html 

10.08.18
A second problem is that the blue colour is quite different from an image to another..
Idea 1: Find Blue
Test of different filter, ways to represent the image: https://gist.github.com/MarcWang/b8e715200775079e4653

13.08.18
Idea 2: Find contour of the nucleus
Not that good because the threshold for the black and white image changes depending on the image
Idea 3: use image minus background instead of the original image alone
Detection of the nucleus done:

Rachel-9ec79107b6cfa203-Screen-Shot-2018-08-13-at-15.41.09.png
Rachel-8f8b08e50c9421b6-Screen-Shot-2018-08-13-at-15.40.48.png

Works even when severals cells:

Rachel-4ee4c8edf9493a0a-Screen-Shot-2018-08-13-at-15.40.26.png



Miscellaneous:

Blob detection:
https://www.learnopencv.com/blob-detection-using-opencv-python-c/

Erosion, dilatation…:
https://docs.opencv.org/3.4/d9/d61/tutorial_py_morphological_ops.html

Detecting shapes:
http://layer0.authentise.com/detecting-circular-shapes-using-contours.html

Idea to have a better mask: 
    # construct a mask for the object colour, then perform
    # a series of dilations and erosions to remove any small
    # blobs left in the mask
    mask = cv2.inRange(image, colourLower, colourUpper)
    mask = cv2.erode(mask, None, iterations=2)
    mask = cv2.dilate(mask, None, iterations=2)
https://github.com/HandMap/boundedRGB/blob/master/src/RGBcontrol.py
https://handmap.github.io/colour-detection-using-rgb-boundaries/

ImageJ
Arivis, Imaris (3D mais payant)