I have a matrix (brain map) Y with the dimensions 53x63x46. Most of the values are NaN but some range from -.07 to 1.5. I would like to visualize this as a heat map. Could anyone please help me how to visualize this? It may also be helpful to present the image as 2D and just show the relevant slices (i.e., important locations).
Update: I found this so I thought I'd try to move the images along the x axis but it doesn't look quite right.
atX=20;
surf(atX * ones(size(Y,2),size(Y,3)),'CData',Y(:,:,atX),'FaceColor','TextureMap');
Related
I have pictures in .dcm format. From Dicominfo I learned that the pixel spacing is [0.9,0.9] mm and the slice thickness is 1.98 mm.
My task: I should get the picture size in real (world) coordinates and then display the pictures in all three projections in matlab.
I had an idea that I would create a matrix in matlab, but it is difficult for me to create the pixel size spacing.
I mean that the pixel in the matrix is like a square and is 0.9mm * 0.9mm.
I don't know if my approach is correct and if there is an easy way to solve the problem.
Thank you very much for every answer
several plotting functions allow you to specify x/y/z positions of each pixel/voxel, including imagesc, pcolor, here is an example using imagesc.
% vol stores your dicom volume
vol=rand(40,50,30);
dx=[0.9,0.9,1.98];
imagesc((0:size(vol,1)-1)*dx(1), (0:size(vol,2)-1)*dx(2), vol(:,:,1))
I have data on the form (x, y, z, v), in other words three spatial coordinates and one velocity magnitude. I would like to plot this in 3D, where the velocity magnitude is shown using color.
What is the best way to do this in MATLAB?
I assume you have trajectory data, so that your spatial coordinates represent the trajectory through space of one or more particles. In that case:
Have a look at quiver3 or coneplot.
If you want colored arrows, then have a look at quiver3d or quiverc (2D only) on the File Exchange.
If you only have 3 spatial coordinates and speed (= velocity magnitude), then your best bet is scatter3.
I could go on, but could you give me a bit more detail on what you want exactly?
Have you tried surf(x,y,z,v)?
I would like to find residuals of my solutions. However, each solution uses a different grid, thus I would like to interpolate the solutions in 2D to a mesh grid for each solution such that I can easily find the residuals.
I used griddata which seems to work, but it doesn't work very well in regions of discontinuities and near edges. I would like to interpolate data of flow over a sphere for example. The area of the sphere should be confined to zero since that is outside of the grid boundaries; however, after using griddata, there's some non zero values in the sphere region. I also get a warning saying there were duplicate x and y points.
Does anyone know how to preserve the integrity of the sphere after using griddata? I've double checked the original x,y data, and the area of the sphere all have values of 0.
Thank you. I hope that made sense.
Best,
Yuki
So I have two vectors*(x & y)* with x and y co-ordinate data points. I would like to put these points on grid kinda like a scatter plot and count the number of points within each grid like the weight of each grid using Matlab.
What would you guys suggest is the best way to do this? Any suggestion is appreciated
I assume you mean that you want to perform a 2D histogram of your x-y data.
You can use several tools from the file exchange:
http://www.mathworks.com/matlabcentral/fileexchange/9896-2d-histogram-calculation
http://www.mathworks.com/matlabcentral/fileexchange/1487
http://www.mathworks.com/matlabcentral/fileexchange/14205-2d-histogram
I am trying to plot a 3d view of a very large CT dataset. My data is in a 3d matrix of 2000x2000x1000 dimension. The object is surrounded by air, which is set to NaN in my matrix.
I would like to be able to see the greyscale value of the surface of the object (no isosurface) but I cannot quite work out how to do that in Matlab. Can anyone help me please?
Given that I a dealing with a huge matrix and I am only interested in the surface of the object, does anyone know a good trick how to reduce the size of my dataset?
The function surf(X,Y,Z) allows you to plot 3d data, where (X,Y) gives the coordinates in the x-y-plane while Z gives the z-coordinate and the surface color.
By default the function does not plot anything for the NaN entries, so you should be good to go with the surf function.
To set the surf-function to use a grayscale plotting use:
surf(matrix3d);
colormap(gray);
This plots the matrix in a surface plot and sets the colormap to grayscale.
In addition, as I understand your data, you might be able to eliminate entire plane-segments in your matrix. If for instance the plane A(1,1:2000,1:1000) is NaN in all entries you could eliminate all those entries (thus the entire Y,Z-plane in entry X=1). This will however require some heavy for loops, which might be over the top. This depends on how many data matrices you have compared to how many different plot you want for each matrix.
I will try to give you some ideas. I assume lack of a direct 3D "surface detector".
Since you have a 3D matrix where XY-planes are CT scan slices and each slice is an image, I would try to find edges of each slice say with edge. This would require some preprocessing like first thresholding each slice image. Then I can either use scatter3 to display the edge data as a 3D point cloud or delaunay3 to display the edge data as a surface.
I hope this will help you achieve what you are asking for.
I managed to get it working:
function [X,Y,Z,C] = extract_surface(file_name,slice_number,voxel_size)
LT = imread(file_name);%..READ THE 2D MAP
BW = im2bw(LT,1);%..THRESHOLD TO BINARY
B = bwboundaries(BW,8,'noholes');%..FIND THE OUTLINE OF THE IMAGE
X = B{1}(:,1);%..EXTRACT X AND Y COORDINATES
Y = B{1}(:,2);
indices = sub2ind(size(LT),X,Y);%..FIND THE CORRESPONDING LINEAR INDICES
C = LT(indices);%..NOW READ THE VALUES AT THE OUTLINE POSITION
Z = ones(size(X))*slice_number;
I can then plot this with
figure
scatter3(X,Y,Z,2,C)
Now the only thing I could improve is to have all these points in the scatter plot connected with a surface. #upperBound you suggested delaunay3 for this purpose - I cannot quite figure out how to do this. Do you have a tip?