Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overlay() doesn't return expected result #62

Closed
hackermd opened this issue Jul 21, 2015 · 3 comments
Closed

overlay() doesn't return expected result #62

hackermd opened this issue Jul 21, 2015 · 3 comments

Comments

@hackermd
Copy link

Following this tutorial I tried the overlay() function on one of my images (DAPI stain):

import mahotas as mh
import numpy as np
from matplotlib import pyplot as plt  # also tried: import pylab as plt

filename = ''  # some image file
img = mh.imread(filename)

thresh = mh.otsu(img.astype(np.uint))
img_bin = img > thresh

img_over = mh.overlay(img, red=img_bin)

plt.imshow(img_over)
plt.show()

This results in a gray image without any coloring.

(img_over[:,:,0] == img_over[:,:,1]).all()

returns True

I'm using mahotas version 1.4 and matplotlib version 1.4.3 and python 2.7

@luispedro
Copy link
Owner

Sorry, I cannot reproduce. Do you still have this error if, instead of loading an image from disk (which I cannot use unless you upload it), you use

img = mh.demos.load('nuclear', as_grey=True)

@hackermd
Copy link
Author

Thanks for looking into it! Using your demo works! However, the color is not red, but cyan.

When I read my image file as follows

img = mh.imread(filename).astype(np.uint8).astype(np.float64)

to get the same data type and scale as the loaded demo image, I get a colored image, but again the color is cyan instead of red. In addition, the the grayscale image (first input argument) is colorized and not the binary mask (second input argument).

The image file is a 16-bit PNG.

@luispedro
Copy link
Owner

Ah! OK, I see the cyan now.

This is partially a matplotlib issue: imshow does not support 16 bit images. See:

matplotlib/matplotlib#2499
matplotlib/matplotlib#2632

Maybe overlay() should convert its arguments to np.uint8. But the real issue, IMHO, is matplotlib's obtuseness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants