matplotlib imshow plots different if using colormap or RGB array

后端 未结 2 1025
一个人的身影
一个人的身影 2020-12-13 10:43

I am having the following problem: I am saving 16-bit tiff images with a microscope and I need to analyze them. I want to do that with numpy and matplotlib, but when I want

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-13 11:27

    I approached this by normalising the image by the maximum value of the given datatype, which said by DrV, for uint16 is 65535. The helper function would look something like:

    def normalise_bits(img):
        bits = 1.0  # catch all
        try:
            # Test integer value, e.g. np.uint16
            bits = np.iinfo(img.dtype).max
        except ValueError:
            # Try float maximum, e.g. np.float32
            bits = np.finfo(img.dtype).max
        return (img / bits).astype(float)
    

    Then the image can be handled by matplotlib as a float [0.0, 1.0]

提交回复
热议问题