-
Notifications
You must be signed in to change notification settings - Fork 13
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
How do I make a tissue mask (with photoshop?) #73
Comments
The mask should be a single-channel image and encoded like this: 0 = background, 1 = foreground, 2 = probable background, 3 = probable foreground. So if you have a png image with white = foreground and black = background, you can convert it to the expected format by running something like this (untested so may need to be tweaked a bit): import imageio as ii
mask = ii.imread("/path/to/mask.png")
mask = mask > 0
# reduce color channels if mask is not single channel:
if mask.ndim == 3:
mask = mask.any(-1)
# optionally, we can use the probable fg/bgd classes to let xfuse convert refine the mask:
mask = np.where(mask, 3, 2)
mask = mask.astype(np.uint8)
ii.imsave("/path/to/encoded_mask.png", mask) Regarding the border, xfuse convert adds some margin to the bounding box of the tissue in order to make sure that the tissue boundaries are sampled during training. The added border has the average color of the edge of the image. In you case, since the tissue extends to the edge of the image, this gives a very weird result. Unfortunately, there is no CLI flag to turn off this behavior, so you would need to modify the code. This can be done by changing the line xfuse/xfuse/convert/utility.py Line 82 in c420abb
to margin: float = 0.0, .
|
I think I cracked it. I managed to make a mask using the following code in python:
Oh yeah before I forget; setting margin: float = 0.0, did not remove the border... Maybe I can solve it by giving the image a white border, and then masking it |
update; I understand now what setting the margin to 0 does. It does work for removing the added border after the initial cropping. I guess the key message here is to always use a tissue mask. (my original question was to remove the colorized border that was added like it was a gene expression area, if you dont use tissue mask). So please ignore all of this. |
Awesome, glad you got it to work! |
I want to run a new analysis, this time with a mask. I can create a mask .png file with photoshop (a black and white image, in grayscale).
When I run the code:
mydir/XFuse/bin/xfuse convert image --image /mydir/XFuse/sections/23O2788/23O2788cirroseHE.jpg --scale 1.0 --mask --mask-file /mydir/XFuse/sections/23O2788/23O2788_mask_grayscale.png --save-path /mydir/XFuse/sections/23O2788_scale1
I get the following error:
So the .h5 file is made; but the assignments GC_BGD or GC_FGD or GC_PR_BGD or GC_PR_FGD need to be made - I understand I need to tell him GC_BGD is background (black) and GC_FGD is foreground (white). But how do I do this?
This is my mask made in photoshop:
If I run
python visualize_tissue_masks.py /mydir/XFuse/sections/23O2788_scale1/data.h5
to visualize the mask, I don't get a mask, but I do get the big border (which I did not ask for).So, (i) How can I make a mask
and (ii) How can I get rid of the border?
The text was updated successfully, but these errors were encountered: