0

I want to remove the background noise from microscopy images. I have tried different methods (hist equalization and morphological transformation methods) but I got the conclusion the best method is to remove low intensity pixels. I can do this using photoshop: enter image description here As you can see, figure A is the original one. I have included the histogram, shown in the bottom insert. Applying the transformation in B, I get the desired final image, where background is removed. See the transformation I have applied in the bottom insert from B.

I start working on the python code:

import cv2
import numpy as np
import matplotlib.pyplot as plt


img = cv2.imread('lamelipodia/Lam1.jpg', 1)



#get green channel to gray
img_g = img[:,:,1]

#get histogram
plt.hist(img_g.flatten(), 100, [0,100], color = 'g')

cv2.imshow('b/w',img_g)
#cv2.imwrite('bw.jpg',img_g)
plt.show()
cv2.waitKey(0)
cv2.destroyAllWindows()

I converted the figure to black and white enter image description here

and got the histogram: enter image description here Which is similar to the one from photoshop. I have been browsing google and SO but although I found similar questions, I could not find how to modify the histogram as I described.

How can I apply this kind of transformations using python (numpy or openCV)? Or if you think this has been responded before, please let me know. I apologize, but I have been really looking for this.

6
  • 1
    google "threshold opencv python", click the first hit, read docs.opencv.org/3.3.1/d7/d4d/tutorial_py_thresholding.html, apply :) or maybe I don't understand what your problem is. you sound like a guy who should be able operate google Commented Nov 21, 2017 at 17:03
  • I saw this page before, but none of the methods helped me... let me read it again and see if this time I am able to find the way. Either way, I will come back here Commented Nov 21, 2017 at 17:12
  • Ok, you were right. I used : ret,thresh5 = cv2.threshold(img_g,150,255,cv2.THRESH_TOZERO). Now I understand. If any pixel is minor than 150 make it zero. I guess this is difficult to read from the function, since the THRESH_TOZERO change the meaning of the transformation. I will update the post, so it is clear the result, thanks Commented Nov 21, 2017 at 17:23
  • they actually give a visual example for each mode ;) write an answer to your question or delete the question. you should not add solutions to a question Commented Nov 21, 2017 at 17:28
  • 1
    not sure what page you read but the link I gave you shows a specific example for evey mode: input image, output image and even the code that produced the example. but you're right, reading that stuff needs practice and you have to read carefully. Commented Nov 21, 2017 at 17:35

1 Answer 1

1

Following Piglet link: docs.opencv.org/3.3.1/d7/d4d/tutorial_py_thresholding.html,the function is needed for the goal is:

ret,thresh5 = cv2.threshold(img_g,150,255,cv2.THRESH_TOZERO)

This is not easy to read. We have to understand as: if any pixel in the image_g is less than 150 then make it ZERO, keep the rest the same value as it was. If we apply this to the image, we get: enter image description here

The trick on how to read the function is by the added style. For example, cv2.THRESH_BINARY makes it read it as: if any pixel in the image_g is less than 150 then make it ZERO (black), the rest make it 255 (white)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.