help > extract multiple slices from a 3D dataset at one time in PNG\JPG format
Showing 1-9 of 9 posts
Display:
Results per page:
Jun 1, 2018  04:06 AM | jumatay - University of Saskatchewan
extract multiple slices from a 3D dataset at one time in PNG\JPG format
Hello,


I am using MRIcron to convert my images Nifty (.nii) to PNG manually. However, it took me so much time to get 160 slices from the original 192 slices. And I tried to get multiple slices at one time on Matlab, but the image quality is different (the one from MRIcron looks better).

Does this difference matter? I am using these images for image classification via deep learning CNN network. (Please check the two images for the same slice converted from both MRIcron and Matlab).

Also, Could someone please tell me the easiest and fastest way to extract multiple slices from a 3D dataset at one time in PNG format. 

Cheers,

Jumatay
Attachment: 1.docx
Jun 1, 2018  10:06 AM | Chris Rorden
RE: extract multiple slices from a 3D dataset at one time in PNG\JPG format
For scripting you should use MRIcroGL. The pre-release includes the ability to program in Python (in addition to Pascal) and the ability to creates orthongonal-slices with lines showing where the other slices come from. However, if you just want single slices you can use a classic "for" loop to generate each slice. The issue I see with your Matlab output is that you have not set the window center and window width (image brightness and contrast). The "wobble" script that comes with MRIcroGL shows a for loop. The Python and Pascal scripts below illustrate how to generate the attached image :

#PYTHON
import gl
gl.resetdefaults()
gl.colorbarvisible(0)
gl.loadimage('mni152_2009_256')
gl.overlayload('motor')
gl.overlayminmax(1, -4, -4)
gl.mosaic('h -0.2 a -24 -16 40 50 60 70 s x r 20')
gl.savebmp('cutoutPython.png')

#PASCAL SCRIPT
begin
resetdefaults();
colorbarvisible(false);
loadimage('mni152_2009_256');
overlayload('motor');
overlayminmax(1, -4, -4);
mosaic('h -0.2 a -24 -16 40 50 60 70 s x r 20');
savebmp('cutoutPascal.png');
end.
Attachment: cutaway.png
Jun 1, 2018  11:06 PM | jumatay - University of Saskatchewan
RE: extract multiple slices from a 3D dataset at one time in PNG\JPG format
Hello Rorden,

That's very kind of you!

Cheers,

Jumatay
Jun 2, 2018  10:06 PM | jumatay - University of Saskatchewan
Convert several MRI slices into one slice image
Dear Rorden,

If you don't mind, I would like to ask some questions.

My data matrix size is 192*192*160, and it has 192 slices in the coronal plane.

Now, first I need to delete some slices, which are noise images and non-tissue images, and this part differs in scans. (for each patient, the number of removed slices are different). Second, I wanna divide the rest slices into 20 stacks of images and convert all slices into one image within each stack. (Please check the one example case in the attachment: if I remove 32 slices, and I left 160 slices to be divided into 20 stacks with 8 slices in each stack, then convert all 8slice into one image).

My question is:

(a) remove noise images and non-tissue images
(b) divide the rest slices into 20 stacks, and convert all images into one image within each stack

I am just familiar with MRIcron, therefore, could you please give me some suggestions on software and methods?

Cheers

Jumatay
Jun 2, 2018  10:06 PM | Chris Rorden
RE: Convert several MRI slices into one slice image
For simple visualization you can simply only list the slices that you want to save to your bitmap, this allows you to skip whichever noisy slices you want.

Take a look at the second example here
  https://www.nitrc.org/plugins/mwiki/index.php/mricrogl:MainPage#Mosaic_Views
which you can generate with this script

begin
 resetdefaults;
 colorbarvisible(false);
 loadimage('mni152_2009_256');
 overlayload('motor');
 overlayminmax(1, -4, -4);
 mosaic('h -0.2 a -24 -16 40 50 60 70 s x r 20');
end.

Remember that the bitmap images saved use the popular PNG format with 8-bit per color precision. For analyses you will want to stick with your raw data and not down sample the precision. If you have multiple people, you could normalize the images from each individual using SPM - this will get them to be the same size and have the same bounding box. Then you can view similar slices with different people without there being a different number of noisy slices for different people.
Jun 3, 2018  02:06 AM | jumatay - University of Saskatchewan
RE: Convert several MRI slices into one slice image
Dear Rorden,

Thanks for your fast and helpful answers!

Jumatay
Jun 4, 2018  02:06 AM | jumatay - University of Saskatchewan
MRIcrogl Installing issue
Dear Rorden,

I'm sorry for asking so many questions. I appreciate your time in responding to whatever you can when you are able to find the time.

Thanks for recommending me to use MRIcrogl, and I am new to MRIcrogl. I was trying to use scripting to get 20 slabs via the "exploded brain" method, however, I was not able to run the MRicrogl software and also the dcm2niix.  I've tried with different versions of MRIcrogl, but it shows the same error each time.

Please check my installation error in the attachment. By the way, my lab computer has Win 7, 64-bit Operating system.

Beast regards,

Jumatay
Attachment: mricrogl.PNG
Jun 4, 2018  10:06 AM | Chris Rorden
RE: MRIcrogl Installing issue
MRIcroGL requires OpenGL 2.1 (which was released in 2006) or later. Typically, if you see an earlier version it is because you are running a virtual machine (which only supports immediate mode). I suggest you try a modern Windows, MacOS or Linux machine and run MRIcroGL locally from the computer not via a virtualized environment. If you are running a virtualized environment you might want to check the settings, for example VirtualBox has an option "Enabled 3D acceleration" that allows you to use modern OpenGL if selected.
Jun 4, 2018  07:06 PM | jumatay - University of Saskatchewan
RE: MRIcrogl Installing issue
Dear Rorden,

Thanks for your kind help.

Best wishes,

Jumatay