Showing posts with label Slicer. Show all posts
Showing posts with label Slicer. Show all posts

Tuesday, December 1, 2009

Data or Hypothesis?

Skull of modern human (Homo sapiens), reconstructed from CT scan of original specimen using 3D Slicer 3.4. Data from OUVC 10503, downloadable at the WitmerLab web page.

As the headline says: data or hypothesis? Discuss.

Thursday, March 5, 2009

3D Slicer: The Tutorial Part VI

Nick (of why I hate theropods) posted a question today on this blog, asking if there was a way to save models from Slicer as STL files. So, here's a quick post explaining how to do just this.

Why would you want to do this, if there's a perfectly good VTK-format model exported by Slicer already? Well, VTK is an industry standard that is good for many open source software packages, but most commercial packages don't deal well with the format. So, STL ("stereolithography") files are a happy medium. STL format has its own issues, but is nearly universally read by computer modeling programs.

In order to get a start on exporting STL's from Slicer, let's return to where we picked up from the last tutorial. Load all of your files (you saved the model and label map after the last tutorial, right?). This should give you the brain in the middle of the 3D viewer. For some unknown reason, say you want to export this brain as an STL for post-processing in another program. Luckily, it's a relatively easy thing to do!

First, switch to the "Models" module, by selecting under the "Modules" drop-down menu.
Then, click on the "Save" tab, to expand this option. Hit the "Save Model" button.

A dialog box comes up, and you can choose an alternative from the default (VTK) under the "Files of Type" option. In this case, select "STL."
Choose the name and location for your file, hit save, and you're done!

Sunday, March 1, 2009

3D Slicer: The Tutorial Part V

Finally. . .the long-awaited continuation of our Slicer tutorial! As a reminder (or for those who are just joining us), 3D Slicer is an open source program designed to reconstruct and present three-dimensional datasets such as CT scans.

In the previous segments of the tutorial, we learned how to load data, view data, segment the data, and create a simple model. In this part of the tutorial, we'll explore some of the editing tools for more sophisticated segmentation. This section assumes that you're already familiar with the basic features of Slicer (essentially, those features outlined in previous posts). Thus, I'm going to gloss past some of the steps we've already covered (loading data, saving data, etc.).

Also, note that I'm using 3D Slicer Version 3.3 Alpha. I like working at the bleeding edge of the software, but the features I discuss should be pretty operational in version 3.2 or earlier. I did notice a bug with one of the tools (the change island tools) in the 3.2 alpha that I had, but this seems variable across operating systems. Most of you already know that I run my build of Slicer in Linux, but the tools are all the same if you're using Windows or Mac.

For ease of presentation, we'll switch datasets from the fossil ankylosaur of previous sections to a modern alligator with the flesh still attached. This specimen is just a little easier to work with as an example.

Note: If you experience issues with graphics (a white screen where a CT slice should be, for instance), experiences suggests that turning off graphical effects in your OS will solve the problem.

A New Dataset
First, download and extract the alligator dataset from the Witmer Labs web page. For ease of access and organization, let's create a folder to store all of our data files and CT slices--in this case, I'm calling my folder "gator." Place the CT data in there (Alligator_mississippiensis_OUVC9761_DICOM-data should be the folder name), and then we're ready to get to work.

As before, load the CT volume into Slicer (accessible through the File-->Add Volume menu).
For ease of viewing, I changed the window and level settings under the Modules section of the toolbar, by selecting "Volumes". In the Volumes section that pops up, hit the display tab. Now, you can adjust the window and leveling options. I used settings of 1600/250 (you can type this in the dialog box). As you'll note, the bone and flesh will stand out more crisply now, versus the default settings.
Now, let's switch to a single slice view, for the red slice (it's labeled as the axial slice here). Zoom in an appropriate amount, to get a better view of what's going on.
The white areas are bone and teeth, the gray areas are flesh (muscle, skin, fat, etc.), and the black areas are air. Note the nasal passages and sinuses in the middle of the skull. Areas of air elsewhere (such as in the lower jaw) are probably due to a mild amount of decomposition after the death of the animal (yes, this is only a severed gator head, not a live animal).

Now, move to the editor (as a reminder, you'll find it next to "modules" and start a new label map. In the box for "Name for label map volume," call it "gator." (I know, not very creative).
Next, let's threshold the label so that only the skull is highlighted. Click the "threshold" button, and adjust it to something that gives you a good picture of the bone. I found a lower setting of 300 and the default upper setting for the range did pretty well in my book.
Do note that if you're using your reconstructions to measure things like volumes, surface areas, etc., you'll want to be very careful about how you threshold (reasons behind this could fill another post altogether). For the purposes of our reconstruction to just show morphology, it won't make much of a difference.

Taking a New Path
So far, we haven't done anything new over the previous sections of the tutorial. You could create a model right now and have a nice gator skull to look at. But, what's the fun in that? Now, let's really take a look at the editing tools in Slicer.

Before we get started, let's save our work so far. This will guard against the annoyance of a glitch, crash, or unintended mouse click that could ruin our hard-earned segmentation efforts. I'm going to save the whole batch in that "gator" directory I created earlier, following the steps outlined a few posts back. Make sure to save both the scene and the data files.

At this point, you may notice that part of the gantry is selected in our default blue color. If you were to make a model right now, this (and any other little bits of noise) would be rendered and obstruct our view of the skull itself. Fortunately, there is a really easy way to get around this: the "change island" tool.

In Slicer, an "island" is a group of contiguous pixels in a label map. All pixels of a single label color that touch each other in the three-dimensional image stack are part of this island. So, the "change island" tool works something like the paintbucket tool in Photoshop or GIMP. You can use it to quickly and easily change the color of a massive area! However, you much be careful that there aren't any "leaks" into an area you don't want filled.

You'll find the "change island" button in the fifth row of the second column on the editor toolbar at the left side of the screen. Click on it, and some options will show up. First, let's change the label color to "5". This means that the blue label will change color to red. The other option, scope, can be left as is for now. Scope just tells you whether you want to fill across the entire label volume or just within a particular slice.
Once we've changed those options, click on a blue area within the jaw. Your computer will chug along for a few moments (the speed of the chugging depends largely on the speed of your processor--a faster computer is always better, regardless of what data analysis program you are using), and then you should notice a major portion of the label map turn red. The gantry and a few other isolated flecks remain blue (label map value "1").
Next, go to location 60 (type it in the dialog box towards the upper right corner of the screen, and hit enter). Towards the bottom of the gator head, you'll see four blue areas. These are the hyoid bones. Let's segment them in a peach color (label map value "2"). It is helpful to zoom in a bit, to make click placement easier. As before, change the label color to "2", and click on each of the four islands of pixels, one at a time.
Your computer will chug along again, and then you should have the hyoids segmented out pretty nicely. It is a good idea to segment each segment of the hyoid individually--that is, wait for the color on one to change before clicking on the next. This will avoid disappointment if you make a poorly-placed click.
Now is a good time to save your hard work, before we move on to the next step.

Let's Make An Endocast!
If you're like me, you were first fascinated by CT scanning as a way to glimpse internal morphology or make renderings of anatomical structures. So far, everything we've done is interesting, but not much better than picking up a real specimen and turning it over in your hand. A great deal of research lately has centered on making digital endocasts of structures such as the brain, or sinuses, or neurovascular canals. Now, we're going to make a quick-and-dirty endocast of our alligator.

First, a brief digression. Making quality digital endocasts is a skill and an art, requiring anatomical knowledge as well as a bit of finesse. Give the same dataset to three different paleontologists, and I guarantee that you will get three slightly different versions of the endocast. It all depends on thresholding, patience, and interpretation. One of the real keys is practice--you will not necessarily get a research-ready endocast on your first attempt. As you gain experience, you'll quickly figure out where to draw the line for boundaries, etc. All of this will make a difference in the final reconstruction (and is an extremely underappreciated and underplayed aspect of those fancy figures you see in papers by me and the other CTers out there). In other words, your first attempt may not be pretty--but it's a step in the right direction!

Ok, let's skip to slice 95. For now, we'll consider that to be the end of the endocranial cavity (not strictly true, but it works for this tutorial).

In the figure below, the mouse pointer is in the space of the endocranial cavity. This is what we're going to fill up to create a virtual brain (yes, yes, I know that the endocast is not synonymous with the brain - just deal with it!).
We're going to use the "change island" tool, with a twist. If we leave the scope for this tool at "All," we'll get a nasty surprise. The space of the endocranial cavity is, right now, contiguous with a whole lot of nothing. This means that trying to change everything at once would spill out into the entire label map, leaving a skull surrounded by a sea of "brains".

So, let's do things differently. Select the "change island" tool, and then change the color to 6 (green brains!). Next, change the scope to "visible". This means that only the slice currently in view will be affected. Move to the endocranial area, cross your fingers, and make a click.
If all goes well, this little area will turn green! We're on the road to a gator brain.
Hit the back arrow to move to the next slice. Repeat as before, for another two or three slices.

Tedious, huh? It would be really nice to find a way to automate the process. Well, now we can think about using the change island tool in a modified way. As you'll recall, we need a closed contiguous area of pixels in order to avoid brain spillage. But, the endocranial cavity is full of holes! In order to get around this, we'll create a "dam" of pixels.

One side of the dam is already in place. We'll just have to create the other side, now. As you scroll back through the brain, you'll find that it's a happy isolated space until slice 85 or so.
So, isolate this space. Now, scroll forward to slice 88 or so. Change the scope to "All," and click in the middle of the endocranial cavity. Once again, things will chug along for a bit. Once it's done, you can scroll back and forth and notice that the areas you had left blank are now filled in. How cool!
Now, let's turn our attention to slice 84. On the left side, you'll notice a little squiggly canal heading away from the endocranial cavity. In some cases, you might want to keep it. But for now, those sorts of things are just extraneous annoyances.

Introducing the Paint Tool
Zoom in to the endocranial cavity, and drag it so that it's at the middle of the screen (using the right mouse button and the mouse wheel, respectively). Now how are we going to keep the change island tool from filling into that canal?

Our answer is the Paint Tool. You'll find it in the editor toolbox, first column and third row. Click on the tool to select it. Now, if you move your mouse pointer across the slice, you'll see a big, big radius of effect. Not what we want!
So, let's change the radius of our paintbrush. On the left side of the screen, you'll see a tool just for that. You can click on it and drag to move by integers, or enter a decimal value (in millimeters). For this slice, I found a radius of 0.25 or 0.5 to be pretty good. So, type this in the dialog box. Now, when you move the pointer over to the slice, you'll notice that the area of effect is much, much smaller.
To block off this area, now just click and drag along the area you wish to enclose. Once you release the mouse button, you'll notice that a little green section is now in place.
If you made a mistake, just hit the "undo" button in the lower right corner of the editor toolbox.

Now, select the change island tool, and make sure it's set to "visible." Click within the area of the endocranial cavity, and you'll notice that our green brain goo stays confined to the area we want!
Making Some Progress
As you've probably noticed, the paint tool is perhaps a little haphazard for some processes. Sometimes you might accidentally overwrite part of the skull (the red colored label). In this case, just uncheck the "paint over" option. Nice and neat!

Continue on, filling in holes at the edge of the endocranial cavity up until slice 34 (for the last few, you'll have to delineate the entire bottom of the cavity).
Then, go back and use the change island tool to fill in all of the slices for the brains. Once you've done that, save your work.

Modeling Your Efforts
Now, let's make an endocast! As a shortcut, click on the "MakeModel" button (seventh row, second column). Under name, type in "Brain" and then hit "Apply."
This will create a model for the label map currently selected (in this case, the #6 green). The model maker will run in the background for awhile--you'll see a little progress indicator at the bottom of the screen.

Once the model maker is done, change the view to "3D Only Layout" (using the fourth buttom over from the right, at the top toolbar).
If you're lucky, you'll see your first digital endocast! If the model isn't visible, it's probably because it is still processing. Once the model shows up (this might even take up to a minute or two), you can click and drag to change the orientation.
Finishing Up
Once again, save all of your work. Your model will be saved along with the label maps, and then you can take a well-deserved break!

Here ends part V of the tutorial. In the next part, we'll take a look at some ways to visualize your endocast in relation to the rest of the skull.

Saturday, December 13, 2008

3D Slicer: The Tutorial Part IV

Wow, there sure are a lot of steps to make a three-dimensional model from CT scan data. So far, we've loaded data, looked at the data, and segmented the skull in preparation for making a model. Now, we're really and truly ready to make the model.

New Beginnings
Just as you did at the beginning of this tutorial, start Slicer. Now, instead of doing everything from Square 1, we'll just reload the previously saved data files. Under the "File" menu, select "Load Scene." A dialog box should come up. Navigate to the directory where you saved your scene file ("ankylosaur," right?), and click on it. At right, you'll see a file called "anky.mrml." This is your scene!

Select this file, and then hit the "Open" button at the bottom of the dialog box. You'll see a little message that indicates the old scene is being loaded.

After a few seconds, you'll notice that everything is right back where you left it! Labels, DICOMs, all of those are loaded.

Seeing in 3D
You're probably wondering when and if you'll ever get to make a 3D model. So, let's get down to it!

We're now going to create a 3D surface model of the segmented data. In order to see what we're doing, let's first change the views from the single slice to one that will allow us to see the 3D image we're creating. Go up to the toolbar, and find the layout button (it should say "Choose among layouts for the 3D and Slice viewers" when you mouse over it). Click on it to bring up the menu of possible views, and click on "Convential layout." The lavender-colored area is where the completed 3D model will eventually reside.
Click on the "Modules:" button on the toolbar, and go down until you find "Model Generation." Another little submenu comes up, and click on "Model Maker." Now, the left-most side of the Slicer screen will change to show the "Model Maker" parameters. We'll want to change a few of these in order to get going.


First, you see a little option called "Parameter set". Click on the up or down arrows next to this, until you find "Model Maker1".

Below this you see options for "Input Volume" and "Models." Click and hold on the "Input Volume" option, and select "skull." This is the label map we created earlier. Next, click and hold on the selector next to "Models," and select "Create New Model Hierarchy."

Finally, you'll see a little area where you can type in "Labels." As you may remember, our label color for the skull was "5" (vessels). If you forgot this, you can just slide your mouse over the segmented images in the lower right part of your screen. As you slide over the red areas, you'll see a little indicator in each CT slice viewer that says, "Lb: 5.0". Slide off of the red areas, and the indicator goes to "Lb: 0.0". "5" is the color of your segmented bone, and "0" is the unsegmented, black areas. So, in the "Labels" area at left, type "5".

Now for the moment of truth. . .hit "Apply," and sit back and relax while your model is created! Things will go gray at the left of your screen while the model is computed, and at the bottom of the screen a little progress indicator gives helpful information.

After about 20-30 seconds (or more, depending on the speed of your computer), a model will appear in the 3D viewer. All of your hard work has paid off!
Looking at the model
Most likely, you can't see the entire model right now. So, change the view (under the layout options button) to the 3D only layout. Just like in the slice views, you can zoom in and out, and even rotate the image.

To zoom, hold down the right mouse button and drag up and down on the screen. Or, spin the middle mouse wheel. To pan the image, hold down the middle mouse button drag around the screen. To rotate the image, hold down the left mouse button and drag. You're getting a privileged look at a rare dinosaur specimen!

Changing views
Of course, now you've got a red ankylosaur skull on a lavender background, with pink lines going through the middle of everything. Fortunately, Slicer is remarkably customizable.

In the lower left part of the screen, you'll see a set of buttons under the title of "Manipulate 3D View." To change the background color, find the button that pops up a context menu of "Toggle visibility of elements in the 3D view". It looks like a little eye. Click and hold, and select "Black background." You should see the background of the 3D view change to - you guessed it - black. To get rid of the pink box and axis labels, go back to the same button, and deselect the options for "3D cube" and "3D axis labels."
Now, let's make our ankylosaur skull a more "natural" color. Under the "Modules:" drop-down toolbar at the top, select "Models". The bar at left will change, and you'll see a whole new set of options.

Click on "Load" to contract this set of options, and click on the "Hierarchy & Display" bar to expand this area.

Under the "Model Hierarchy" area, click on "Model." This is the model of the skull that we just created. Now, we can change some colors. Because the options go for quite a ways, you may have to use the scroll bar to go down a little. Click on "Set Color..." (either the red colored box or the text next to it).
This brings up a whole new dialog box, with a world of colors! On the area at right, you can drag around to find a new color. Alternatively, if the choices overwhelm you, there is another way. You'll notice a few tabs above the color palatte. Click on the one that brings up the "Basic Colors" option. A much more limited set of options now appears.

In the interest of making it look like an unfossilized skull, select the white at the end of the fourth row. Then, hit "OK."

You've now got a sparkling-white Ankylosaurus skull! You can rotate, zoom, and inspect morphology to your heart's content.

Finishing Up
For the end of this tutorial, let's save our work to date. Under "File," select "Save." Everything should be the same as before, except there's a new entry for the skull model.

Check to ensure that it's being saved in the ankylosaur directory (it should be, if all went well), and hit "Save." You're all done! The model is now saved in VTK format, and can be reloaded later.

That's all for this phase. You've loaded data, segmented it, created a model, and saved your work. In January, I'll begin the next phase of the tutorial - talking about how to segment out specific structures (e.g., the endocranial cavity), make measurements, and the like. For now, enjoy your newfound skills!

Friday, December 5, 2008

3D Slicer: The Tutorial Part III

Alrighty, now we're really going to get something done with Slicer. So far in this tutorial series, we've learned how to start the program and load data, as well as how to take a look at these data in various views. In this part of the tutorial, we'll segment the data. To get started, you'll want to have completed all of the steps in the last two posts. Go back to the "Red Slice only layout," and fit it to the window.

Thresholding
Looking at the CT data is fun, but we all know this isn't the only reason for using CT scans. Let's make a three dimensional rendering of the data!

The process of selecting the "useful" parts of a CT image for further analysis (whether creating a 3D model, volume measurements, or whatever) is called segmentation. In Slicer, you don't change the actual slices, but create a "label" that is overlain on top of the image. The label is color coded to indicate what you're trying to segment - for instance, you might have all of the bone in blue and the endocranial cavity in red.

Slicer accomplishes all of its segmentation in the "Editor." To get there, go up to the top toolbar, and click on the drop-down menu next to "Modules:", and then select "Editor." The screen will change at the left, and you should see a whole new set of gizmos to work with.

First things first, though. We'll want to name our label map. The default is "Working," but let's make it something more intuitive - so, type in "skull" as the label map name, and then hit the "Create Label Map" button immediately below the dialog box.

Things should chug along for a moment, and then you'll see the screen jump back to the default "middle" slice of the CT stack. This is ok - as you learned already, it's easy to navigate!

The first important thing to note is that at the left of your screen, under tools, you'll see a little blue box next to a box with "Label 1". This indicates the color of the label map that you're creating. If you want a different color, you can hit the up or down arrows, or click on the colored box to bring up all of the available colors. Try the latter approach.

Then click on "Vessels," to change everything to a nice red. You'll notice all of the colors have funky, non-paleontological names. This is because the Slicer software was originally developed for biomedical applications, particularly brain imaging.

Now, we're ready to segment! There are all sorts of different ways to segment. . .you can outline each individual element on each individual slice (tedious after the first 20 or 30 slices!), use a "fill" tool to fill certain areas, or just a plain-old threshold. For starters, we'll use a threshold, because it's quick, easy, and useful.

You'll note a whole series of buttons on the left column of the Slicer program window. As you mouse over them, little labels will pop up to guide you. Find the one with a white-to-black gradient on it; it should say "Treshold" as your pointer passes over it. Click on it. Now, things start to look crazy!
You'll see a pulsating red overlay on the CT scan image at right. . .everything that is in red will be segmented if you hit the "apply" button. But, you'll notice that lots of unnecessary junk is highlighted. To get rid of this, you use the slider bars at the left side of the screen. Just like with the windows and level dialog, you can also type in numbers. Slide the bar around until only the skull is highlighted, but not the CT gantry at the bottom of the image, or the air, or anything else. If found good results around a minimum of 560.51 and a maximum of 4691. While you play with this, you can slide back and forth through the stack, to see how the threshold works for the entire skull. You may have to adjust to find something that works throughout.

Now, hit the "Apply" button. Things chug along for a moment or two, and then it's all done! The threshold dialog will disappear, and your image is now thresholded.

So, the whole image is now segmented. To prove this, you can slide back and forth through the stack of images, and you'll notice that the skull is colored in red throughout. But remember--unless you hit "Apply," your hard work for thresholding won't be remembered by the program.

Saving Face
You (and your computer) have been working pretty hard so far. Before we go any further, let's save your efforts. It's a good idea to save frequently, to protect yourself against data loss.

There are two important things you'll want to save so far. . .your label map (the information on how you segmented the skull) and the "Scene" file. The scene file contains information on all of the files you loaded so far - it makes it easy to quickly reload everything without having to load the CT data and label files individually. This doesn't sound like much at this stage, but it can get quite complicated when you have multiple volumes or label maps involved!

The latest versions of Slicer make it pretty easy to save your work. Under the menu at the very top, go to "File" and then click on "Save." The resulting dialog box has two main portions: Save Scene and Save Data.

First, let's choose a name for our Scene File. Click on the little folder next to Scene File. A new dialog box comes up, and you can choose where to save the file. You may wish to create a new folder on your Desktop called "ankylosaur" to contain these files. I did this, by clicking the "create folder" button near the top of the dialog.

Then, I named my scene file "anky" (by typing this in the "File name:" box, and hit the "Save" button.

The scene dialog box disappears, and we're back to the previous "save data" dialog.

Under "Save Data", you'll see two listings, identified under "Node Name". One begins "1.2.840.113...", and this is the original DICOM file we loaded. Because it wasn't ever changed, there is no reason to save this. Below that, you'll see "skull." This is our label map, and we want to save it. Slicer's default is to place it in the Slicer program directory. But, we don't want to do this. Instead, click on the area next to "Data Directory." This brings up a new menu.

Navigate to the "ankylosaur" folder that you created previously, and select it. Hit "OK." Now, you'll see that the label map will be saved to this directory.

We're finally ready to save the files - so, hit the "Save" button at the bottom of the dialog box. Your computer will chug along for a few seconds, and then it's finished. The dialog box will disappear, and everything should be saved (assuming you followed the directions successfully).

Let's quit Slicer, and go enjoy a bit of your day away from the computer. Under the File menu, select Exit. The program will ask if you really want to leave (I know, you were just starting to have some fun!), and hit "Yes."

Here ends Part III of the tutorial. . .in the next post, we'll actually make a digital model of the skull!
  翻译: