open-discussion > MRIcroGL Visualization demos
Showing 1-12 of 12 posts
Display:
Results per page:
Oct 6, 2019  05:10 PM | Mikolaj Pawlak
MRIcroGL Visualization demos
Dear Chris, 
Thank you very much for creating MRIcroGL resource for visualization. I've created a spinning skull thickness image. 
https://photos.app.goo.gl/PU4K2xws3aE9n1...

The script goes as follows:
import gl
gl.resetdefaults()
ktime= 40
ksteps= 180
gl.resetdefaults()
gl.loadimage('/Users/user/path/CT_Philips_thr300_bin_char_LocThk.img')
#adjust contrast to show thickness
gl.minmax(0, 0, 10)
gl.colorname(0,'blue2red')
for x in range(1, ksteps):
gl.azimuthelevation(0+(x*2),10)
gl.wait(ktime)

Q1: How do I capture a screenshot of every point in the loop using filename_number.extension?
Q2: How do you feel about having a gallery of the visualizations scripts? (Would be so much easier if people share their results)

thanks, 
Mikolaj
Oct 7, 2019  10:10 AM | Chris Rorden
RE: MRIcroGL Visualization demos
This looks nice.
 Q1.) The scripting page shows you how to save a bitmap for each repetition of a for loop. Assuming you have version 1.2.20190902++ or later, an example will appear in Scripting/Templates/Explode. Just remove the comment (#) in front of the line "#gl.savebmp(str(x)+'.png')"
 Q2.) I think the scripting section of the Wiki is a great place to share scripts. The Gallery section of the Wiki allows you to share images. I am not sure whether the NITRC wiki system allows you to insert videos, but you could always link to a video shared on an external site like YouTube from the scripting or gallery sections of the wiki,
Oct 7, 2019  11:10 AM | Mikolaj Pawlak
RE: MRIcroGL Visualization demos
Thanks a lot
Mikolaj
Feb 29, 2020  11:02 PM | Andrew Sun
RE: MRIcroGL Visualization demos
Mikolaj,
I was wondering how you were able to create the spinning skull image. Were you able to do it within MRIcroGL?

I tried running your script, replacing your .img image with one of the standard images in MRIcroGL to see what would happen (I have no scripting experience), and I got this error message:

Running Python script
File "", line 10
gl.azimuthelevation(0+(x*2),10)
^
IndentationError: expected an indented block
Python Engine Failed
Python Succesfully Executed



Thanks,
Andrew
Mar 5, 2020  06:03 PM | Chris Rorden
RE: MRIcroGL Visualization demos
1.) Be aware that the Python language requires you to indent the for loops with white space.
  https://www.geeksforgeeks.org/statement-indentation-and-comment-in-python/
2.) Can you make sure you are using the latest version (v1.2.20191219) and if issues persist tell me the operating system
  https://github.com/rordenlab/MRIcroGL12/releases
3.) does the script Scripting/Templates/Explode show an animation. If so, you could adapt for your usage
4.) Below is an example, notice that the lines after the for statement are indented

import gl
ksteps = 12
ktime= 100
gl.resetdefaults()
gl.loadimage('spm152')
for x in range(1, ksteps):
  gl.azimuthelevation(0+(x*12),10)
  gl.wait(ktime)
Mar 6, 2020  12:03 AM | Andrew Sun
RE: MRIcroGL Visualization demos
I was able to get the script to work in the older version (20190902) before I updated simply by adding the correct indents (referencing template script for CT abdo). I've updated and this still works, thanks for the detailed feedback.

I was wondering how you would save what I've made as a video that can be inserted into a slideshow? Apologies for the basic questions.

Thanks,
Andrew
Mar 6, 2020  01:03 PM | Chris Rorden
RE: MRIcroGL Visualization demos
Andrew
The savebmp command allows your script to save an image as a bitmap. If you choose Scripting/Templates/Explode menu item, you can uncomment the final line to save each frame of the animation as a png file
  #gl.savebmp(str(x)+'.png')
you can use your favorite tool to convert PNG files to video animations.
Mar 6, 2020  01:03 PM | Andrew Sun
RE: MRIcroGL Visualization demos
So, if I have something like this, where would the png files be saved? Or how could you specify?

import gl
gl.resetdefaults()
ktime= 50
ksteps= 360
gl.resetdefaults()
gl.loadimage('mni152.nii.gz')
for x in range(1, ksteps):
  gl.azimuthelevation(160+(x*5),30)
  gl.wait(ktime)
  gl.savebmp(str(x)+'mni152.png')
Mar 6, 2020  02:03 PM | Chris Rorden
RE: MRIcroGL Visualization demos
You can always explicitly specify the output directory in the filename, e.g. "save bmp('c:/mymovie/'+str(x)+'.png')". If you do not specify your folder, it will appear in your home or Desktop folder, depending on your operating system.
Mar 10, 2020  06:03 PM | Andrew Sun
RE: MRIcroGL Visualization demos
Chris,

As usual, really appreciate the troubleshooting. I was able to turn the MRIcroGL animations to png files, (ktime= 40, ksteps= 180), and tried using ImageMagick to convert the png files into a gif.

I used this 

"convert -delay 10 -loop 0 MNIslice*.png MNIanimated.gif"
then
"convert -dispose previous MNIanimated.gif MNIanimated2.gif"

However, every couple of frames, the gif seems to be including an older frame relative to it's current frame, leading to a weird jump in the animation.

Here's the animation below (both MNIanimated.gif and MNIanimated2.gif look the same):
https://photos.app.goo.gl/kPYpy4f7C3NYCS...

I know it's not really a MRIcroGL issue, but was hoping you can help

Thanks!
Andrew
Mar 10, 2020  08:03 PM | Chris Rorden
RE: MRIcroGL Visualization demos
As a guess, do you have more than 9 frames? If so, zero-padding the filenames of the bimtaps might help ensure they are sorted correctly. e.g. to prevent '11.png' from being ordered before '2.png' you could create '01.png'..'32.png'
  https://stackoverflow.com/questions/339007/how-to-pad-zeroes-to-a-string
Be aware that gif images are limited to 256 colors, so this may lead to artifacts. Sounds like a question for a different forum,
Jan 11, 2021  06:01 AM | warrenfelsh
RE: MRIcroGL Visualization demos
Most programming languages permit indentation, but don't enforce it. Python enforces it with an iron fist, it has caused confusion for many beginners. The error expected an indented block is probably caused by a mix of tabs and spaces and this can lead to some confusing errors. Putting in an extra space or leaving one out where it is needed will surely generate an error message . Some common causes of this error include:
  • Forgetting to indent the statements within a compound statement
  • Forgetting to indent the statements of a user-defined function.

The indentation can be any consistent white space . It is recommended to use 4 spaces for indentation in Python, tabulation or a different number of spaces may work, but it is also known to cause trouble at times. Most editors have an option for automatically converting tabs to spaces. If your editor has this option, turn it on.