NIfTI spatial position/orientation changes after using NIfTI_tools - matlab

I'm using a particular toolbox (Tools for NIfTI and Analyze image) to process NIfTI files with MATLAB, but when I do a simple value modification, the spatial information associated with the image is somehow changed. I can't directly compare the before and after images because they have different origins and/or some slight translation. I did not (intentionally) modify the NIfTI header information. In fact, I used only three commands:
matlab_nii = load_nii('original.nii');
matlab_nii.img(matlab.nii.img > 10) = NaN;
save_nii(matlab_nii, 'new.nii');
Despite not editing any of the header information, only modifying the image values directly, the new NIfTI file has differing spatial properties, making it impossible to compare directly to the original, to verify that, indeed, the modifications took place.
I'm hoping someone has had experience with these tools and has encountered this issue.

Found the solution in one of the answers to this question about NIfTI/MATLAB.
The answer is to use load_untouch_nii instead of load_nii and save_untouch_nii instead of save_nii.
The functions I used initially will apply affine transformation data (if it exists, which apparently it did) to the image. Using these functions results in a direct spatial association between voxels.

Related

How to plot all the stream lines in paraview?

I am simulating the case "Cavity driven lid" and I try to get all the stream lines with the stream tracer of paraview, but I only get the ones that intersect the reference line, and because of that there are vortices that are not visible. How can I see all the stream-lines in the domain?
Thanks a lot in adavance.
To add a little bit to Mathieu's answer, if you really want streamlines everywhere, then you can create a Stream Tracer With Custom Source (as Mathieu suggested) and set your data to both the Input and the Seed Source. That will create a streamline originating from every point in your dataset, which is pretty much what you asked for.
However, while you can do this, you will probably not be happy with the results. First of all, unless your data is trivially small, this will take a long time to compute and create a large amount of data. Even worse, the result will be so dense that you won't be able to see anything. You will get all those interesting streamlines through vortices, but they will be completely hidden by all the boring streamlines around them.
Thus, you are better off with trying to derive a data set that contains seed points that are likely to trace a stream through the vortices that you are interested in. One thing you might want to try is to compute the vorticity of your vector field (Gradient Of Unstructured Data Set when turning on advanced option Compute Vorticity), find the magnitude of that (Calculator), and then use the Threshold filter to pull out the cells with large vorticity. Then use that as your Seed Source.
Another (probably better) option if your data is 2D or you can extract an interesting surface along the flow of your data is to use the Surface LIC plugin. Details can be found at https://www.paraview.org/Wiki/ParaView/Line_Integral_Convolution.
You have to choose a representative source for your streamline.
You could use a "Sphere Source", so in the StreamTracer properties.
If that fails, you can use a StreamTracerWithCustomSource and use your own source that you will have to create yourself first.

MATLAB: How to Retrieve Intensity-Based Registration Data (with imregister) to re-Perform Registration?

I thought this should be a simple task, I just can't find the way to do it:
I am using 'imregister' (MATLAB) to register two medical X-ray images.
To ensure I get the best registration outcome as possible, I use some image processing techniques such as contrast enhancement, blackening of objects that are different between images and even cropping.
The outcome of this seems to be quite satisfying.
Now, I want to perform the exact same registaration on the original images, so that I can display the two ORIGINAL images automatically in alignment.
I think that an output parameter such as tform serves this purpose of performing a certain registration on any two images, but unfortunately 'imregister' does not provide such a parameter, as far as I know.
It does provide as an output the spatial referencing object R_reg which might be the answer, but I still haven't figured out how to use it to re-preform the registration.
I should mention that since I am dealing with medical X-ray images on which non of the feature-detecting algorithms seem to work well enough to perform registration, I can only use intensity-based (as opposed to feature-based) registration, and therefore am using 'imregister'.
Does anyone know how I can accomplish this?
Thanks!
Noga
So to make an answer out of my comment, there are 2 things you can do depending on the Matlab release you are using:
Option 1: R2013a and earlier
I suggest modifying the built-in imregister function by forcing tform to be an output and save that function under another name.
For example:
function [movingReg,Rreg,tform] = imregister2(varargin)
save that, add it to your path and you're good to go. If you type edit imregister you will notice that the 1st line calls imregtform to get the geometric transformation required, while the last line calls imwarp, to apply that geometric transformation. Which leads us to Option 2.
Option 2: R2013b and later
Well in that case you can directly use imregtform to get the tform object and then use imwarpto apply it. Easy isn't it?
Hope that makes things clearer!

Matlab Computer Vision: How to use image in memory for imageSet?

I am currently working on a project at home and hoping to use the Computer Vision toolbox in Matlab to retrieve images from a set that match based on my query image. In fact, the example I'm using from the Matlab documentation here: Image Matching Example
The snag I keep bumping into is that it appears the imageSet class in Matlab only works on files saved to disk. Unfortunately, the work I'm doing has a 4D matrix of an image collection I've created artificially. More specifically, it has the shape (M,N,RGB,I) where
M = number of pixels in X-dir
N = number of pixels in Y-dir
RGB =
size of 3, where each channel for RGB is stored as a page
I = the
image number (up to 10,000, for example)
It seems pretty silly that I have to write everything to files for me to employ the imageSet class object.
So, the question is: Does anyone know a way to create the imageSet object (or similar) without have to write everything to a tmp dir on disk to carry out the analysis, that is, create imageSet from workspace variables?
For the life of me this one had me stumped all weekend. I know I could capitulate and write to files, but somehow that just bothers me.
Any help is greatly appreciated.
You are correct, imageSet only stores file names, and gives you a read method to read a particular image from disk.
In general, if you already have the images in memory, you can simply store them in a cell array. Or, if your images are all the same size, you can keep them in a single multi-dimensional array.
However, in this particular case, you are using bagOfFeatures, which currently only takes imageSet. So you will have to save your images to files.

running NN software with my own data

New with Matlab.
When I try to load my own date using the NN pattern recognition app window, I can load the source data, but not the target (it is never on the drop down list). Both source and target are in the same directory. Source is 5000 observations with 400 vars per observation and target can take on 10 different values (recognizing digits). Any Ideas?
Before you do anything with your own data you might want to try out the example data sets available in the toolbox. That should make many problems easier to find later on because they definitely work, so you can see what's wrong with your code.
Regarding your actual question: Without more details, e.g. what your matrices contain and what their dimensions are, it's hard to help you. In your case some of the problems mentioned here might be similar to yours:
http://www.mathworks.com/matlabcentral/answers/17531-problem-with-targets-in-nprtool
From what I understand about nprtool your targets have to consist of a matrix with only one 1 (for the correct class) in either row or column (depending on the input matrix), so make sure that's the case.

Plot data in google map from matlab

Is there anyway to plot my data consisting of lat/lon and some feature values in google map from matlab. I have certain data points having different properties based upon that I want to show like markers with different color/size on google map. Is that possible
Google Maps allows you to import data in the form of a KML file. There are various tutorials available online that show how to perform this import step (here's one that I just quickly found). Also, here is some basic info on KML from google.
So then the only challenge becomes exporting your data from MATLAB into KML form. If you have MATLAB's Mapping Toolbox, then this is extremely easy. Just use the kmlwrite command.
If you don't have the Mapping Toolbox, already, it's probably a good idea to have if you are performing any sort of complex mapping operations (things get pretty complicated when you try to flatten a round globe into a map). If this is just a one-off project and that toolbox is overkill, then you may be able to manually create a KML file by writing XML from MATLAB (either using xmlwrite or going the very manual route of writing with fprintf).
Additionally, I would not be too surprised if Google Maps allows you to import certain data in the form of CSV files (though perhaps this has limitations compared to KML). If so, you can simply make use of csvwrite from MATLAB to export your data (no extra toolboxes required).
==EDIT==
If you'd like to find out how to convert from CSV to KML, this previous SO post might help.
There is the KLM-Toolbox that doesn't require the matlab Mapping Toolbox:
http://www.mathworks.com/matlabcentral/fileexchange/34694
It should do the job.