general > Export slices with adjusted transparency of DTI images
Showing 1-9 of 9 posts
Display:
Results per page:
Aug 18, 2021  09:08 AM | Anh Nguyen - Champalimaud centre for the Unknown
Export slices with adjusted transparency of DTI images
Hi,

I'm a new QuickNII user and I've been very impressed by how it works and the amount of hours the software saves me. I'd really appreciate if we have the option to export the slices with adjusted transparency and/or svg format of the algned atlases.

Thank you very much.

Anh.
Aug 19, 2021  03:08 PM | Gergely Csucs
RE: Export slices with adjusted transparency of DTI images
Hi Anh,

Happy to hear that you find this application useful.
The story behind the image export looking different from what you see on the display is that the exported images show the area covered by your image inside the atlas. So even if your image is 3000x4000 pixels large, the export is still going to result in something like 400x350 pixels (the atlas has 512x512 pixels in a coronal plane). To combine the two, you can simply stretch the exported image over the real one in some image manipulation software (practically drag its bottom-right corner to the bottom-right corner of the corresponding histological image, and you will suddenly see what was in QuickNII).

I hope this helps.
Best regards,
Gergely
Aug 19, 2021  06:08 PM | Anh Nguyen - Champalimaud centre for the Unknown
RE: Export slices with adjusted transparency of DTI images
Hi Gergely,

Thank you for the prompt reply.
I guess my question wasn't clear. Right now the "Export slices" options give out the Segmentation, MRI and DTI png images of the atlas. They are really informative, but for my purpose, an image of only the outline (hence transparency in the original post) would be tremendously helpful. Is there a way to export only the outline with the current version of the QuickNii for rats?

Thanks.
Anh.
Aug 19, 2021  09:08 PM | Gergely Csucs
RE: Export slices with adjusted transparency of DTI images
Hi Ahn,

Yes, now I understand. While QuickNII can't do such export, in the neighboring topic, https://www.nitrc.org/forum/forum.php?thread_id=12559&forum_id=9082 I tried to collect some ideas how to generate such outlines.

Best regards,
Gergely
Aug 20, 2021  06:08 AM | Anh Nguyen - Champalimaud centre for the Unknown
RE: Export slices with adjusted transparency of DTI images
Hi,

I've been trying out that approach but one thing concerns me. As far as I know, transparency setting methods like image.putalpha() in python set an alpha layer on top of the image. If I set alpha to 0, I lose the outline. If I set alpha to a very low number, the colors of brain regions retain, which interferes with my interpretation of the data. Do you know of any other workaround, preferably in Python/Matlab?
Thanks!

Anh.
Aug 23, 2021  12:08 PM | Gergely Csucs
RE: Export slices with adjusted transparency of DTI images
Hi Anh,

if you know Python, things may be much-much simpler:
import PIL.Image

overlay=PIL.Image.open("segmentation.png")
image=PIL.Image.open("histology.png")

for x in range(1,image.width-1):
  for y in range(1,image.height-1):
    x0=x*overlay.width/image.width
    y0=y*overlay.height/image.height
    p=overlay.getpixel((x0,y0))
    if (p!=overlay.getpixel(((x-1)*overlay.width/image.width,y0))
        or p!=overlay.getpixel(((x+1)*overlay.width/image.width,y0))
        or p!=overlay.getpixel((x0,(y-1)*overlay.height/image.height))
        or p!=overlay.getpixel((x0,(y+1)*overlay.height/image.height))):
      image.putpixel((x,y),(255,0,0))

image.save("outline.png","PNG")
This snippet combines an image (histology.png) with its exported segmentation (segmentation.png) in a way that it draws a 2-pixel wide red outline where segmentation changes, leaving everything else intact.

I hope this helps.
Best regards,
Gergely
Aug 23, 2021  06:08 PM | Anh Nguyen - Champalimaud centre for the Unknown
RE: Export slices with adjusted transparency of DTI images
Hi,

Thanks for the suggestion! The code gave me an error at line image.putpixel((x,y),(255,0,0)): color must be int or single-element tuple. I guess it relates to the format of my histology image?
In general, if I understand it correctly, your code works relatively similar to the function PIL.ImageFilter.FIND_EDGES?

Best,
Anh.
Aug 23, 2021  10:08 PM | Gergely Csucs
RE: Export slices with adjusted transparency of DTI images
Hi Ahn,

Yes, I wrote and tested this code with RGB images in mind ( (255,0,0) is just a simple red color), I think yours may be grayscale, like something from a fluorescence-based technique. Try using a single number instead as the message suggests, like 255.
The snippet does some kind of edge detection, and the extra part is the upscaling of the segmentation image to the resolution of the microscopy image. The edges are going to be 2-pixel wide on the image this way, while doing an edge detection first on the segmentation image and upscaling the result afterwards would result in very thick outlines, also with different width along the vertical and horizontal axes.

Best regards,
Gergely
Aug 31, 2021  11:08 AM | Anh Nguyen - Champalimaud centre for the Unknown
RE: Export slices with adjusted transparency of DTI images
Hi Gergely,

Thanks a lot for the explanation! I couldn't get back to this earlier since I was on holiday.

I'm trying to optimize the code (either vectorization or using Cython) as I have a lot of images and looping pixel-by-pixel really slows down the process. In order to do that, I tried to understand what putpixel() and getpixel() do, but when I ran some debugging, getpixel() returned different values of the image pixels, while it returned none for the overlay (photo attached). I'm not sure how to make of this.
I would really appreciate your inputs and especially your thoughts on vectorization/Cython for optimization.

Best,
Anh.