[SOUND] All right, now that we've gone through the DICOM imaging format, we're ready to start with the NIfTI imaging format. Which is a way to look at objects as 3D images in art and with other neural imagining software. NIfTI stands for Neuroimaging Informations Technology Initiative. It's a standard representation of images, and it's the most common used type of analytic file. These files have been developed to facilitate cross-platform and cross-software interpretability. These images are 3-dimensional arrays, so there are stacks of the individual slices that we saw on on the DICOM images. A way to think about this is we can think of a DICOM as a single sheet of paper and could think of a NIfTI as a stack of papers or as a book. In this table, we're going to do a comparison of the DICOM and the NIfTI formats to get us used to the differences between the two. In the first row we have the file extension for both of the files. So for the DICOM these have a .dcm extension. And for the NIfTI we have a .nii or a .nii.gz extension. Where the GZ extension is for G zipping the file or compressing it, which we'll go over in just a minute. The file representation for DICOM is one slice of the brain. So we solved that extensively in the last lecture. For the NIfTI we have a 3D image of the entire brain, or a 3-dimensional array of numbers. In the DICOM the header contains many fields and has protected health information as well as hospital related metadata. In contrast, the header for the NIfTI doesn't contain patient information, but it does have the imaging metadata such as the pixel dimension that we looked at in the last lesson. the DICOM storage is what we saw in the first lecture where each one of the DICOM images for a subject is stored in an individual file. For NIfTIs, since we only have one image for each file, we can store these altogether for one subject in a single folder. As we were saying before, doing analysis on NIfTI images is much easier than on DICOM, but one problem is that hospitals tend to have DICOM saved on their packs, or if you get them directly off the scanner, they're going to be in a DICOM format. So the first thing we're going to go over is how to convert images from a DICOM format to a NIfTI format. And lucky for us there is already an R package that does this, the oro.dicom package. We're going to use the function dicom to nifti to convert these files. The dicom to nifti produces a nifti R object and when we save this R object we get something with a .nii or .nii.gz extension. All right, so you'll remember in the last lecture, we read in multiple DICOM files to create kind of this list of our 3-D image, so we'll have you go ahead and rerun the things that we did in that lecture off of this slide. So that we can convert this DICOM image into a NIfTI image. So once you've done that, we can go ahead and we can use the DICOM to NIfTI function. So we can take that list all_slices_t1, and put that into DICOM to NIfTI, and then we're going to save the output from that as nii_T1. So if we look at the dimension of nii_T1, we see that this is 512 by 512 by 22. So now we have 22 slices together for our image. And then if we look at the class of this object before we had list, but now we have something of a class NIfTI. And if we go ahead and plot this, it looks the same as it did last time. But here we're plotting the 11th slice of our array. So we have niii_t1 and then we bracket ,,11. Which picks out the 11th slice. There's a package that's created for working with NIfTI files called oro.nifti. And this has a function called writeNIfTI and readNIfTI which we're going to use to write nii objects and to read these into our to do analysis. One thing to note is that the default for write NIfTI is the same NIfTI files in a compressed format. So it will save everything automatically with a .nii.gz. Okay, so lets work with the oro.nifti package. So we're going to go library, oro.nifti, to load the package in. And now let's set our working directory to neurohacking_data/brainix/NIfTi. So now what we're going to do is we're going to save this file that we converted from a dicom to a nifti in this folder. So we're going to create a file name. We picked output_3D_file, and we're saying that is the best string as the variable F name. Now if we use the writeNIfTI function, what we need to do is pass in a NIfTI object which will be called the argument nim. So we say nim is equal to the name of our NIfTI file. In this case, nii_T1, and then we assign the file name. So we say file name is equal to the name that we wish, which is saved in the variable F name. And so now we've gone ahead and written out that nifti file. Let's go and see if that's in the folder that we wanted. So we can use the R function list files to check and see if that file is there. So we're going to use list.files, and we're going to use our current working directory, which we can get using Get W D. And then we're going to look for something that matches the pattern of our file name, which is pattern equals output_3D_file. Now we see that we have this file, in that folder and then it has a .nii.gz extension. We can also see what other files are in there. If we do list.files(getwd( ) and we use a pattern T we see that we have a T1 and a T2 in this file as well. And we're going to go ahead and read in the T2 using the readNIfTIi function, also part of the oro.nifti package. So we'll say nii_t2 is equal to, so we're assigning this as the output of readNIfTI. And all you need to do there, is put the file name. And then we don't normally reorient the images, because we've had some trouble using that function from the readNIfTI. The dimension of this is the same as the T1, so it's 512 by 512 by 22. Okay, I promised earlier that we would talk about the compressed image files and why this is important. When you have a compressed file, it would have the extension .nii.gz. And the reason you do this is it's good for saving disk space and it also makes reading and writing the files much faster. Another great thing is that you can move files from one location to another much more quickly when they have been compressed. It's excellent for scripting and analysis of large imaging populations. But if you don't want to zip your files, you can just use the writeNIfTI function, and pass in the argument gzipped=FALSE. Okay, for those people who don't want to use r to convert their DICOM images to NIfTI images, you can use the program dcm2nii, and we have a citation for that at the bottom of the page, and this is part of the MRIcron platform. Basically this'll convert a set of DICOM images to NIfTI files, and it's great because it can handle multiple formats and file types. But for this course we're going to focus on R, so we put more emphasis on that. Okay, we also mentioned at the beginning of the course a few other file formats. We're not going to go into as much detail about these file formats, but we'd like to mention them here because they do come up when you're working with data. The PAR/REC files are files from a Phillips scanner. So subjects that are scanned on a Phillips scanner will have a PAR/REC file as opposed to a DICOM file. Their software called r 2 a, which can be used to convert PAR/REC files to NIfTI files and we have a link to that down at the bottom. There's also ANALYZE files, and these are what NIfTI files were originally based on, but they have a separate header and image, and so the NIfTI files kind of are an improvement on that because there's only one file that you need to deal with. Then we have the nearly raw raster data, or the NRRD. Which is another less common format but most imaging software can read nrrd.