How to use isosurface() for images? - matlab

I am new to matlab. I have few binary images, as shown below, which I have to display with isosurfaces as a 3d object. I could not understand what input I need to pass to this function, when I have some images. I am referring this documentation.
I have total 22 images which are slightly diffrent from this image:

If your 22 images are all images from the same volume, you can concatenate them into a 3D array with the dimensions of [nRows, nCols, 22]. How you do this really depends upon the format your data is currently in.
You can then pass this 3D matrix (images) directly to isosurface along with an isovalue (I'll assume 1 for demonstration purposes);
FV = isosurface(images, 1);

Related

create the pixel size for Dicom_Picture in matlab

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))

MATLAB imshow for 3D color image

I have a medical imaging matrix of size [200x200x200].
In order to display it, I am currently using imshow3D function, which is an excellent tool, built by Maysam Shahedi.
This tool displays the 3D image slice by slice, with mouse based slice browsing
In my current project, I generate an RGB image for each z-layer from the original input image. The output is a 3D color image of size [200x200x200x3] (each layer is now represented by 3 channels).
The imshow3D function works great on grayscale images. Is it possible to use it to display RGB images?
I took a look at this nice imshow3D function from Matlab FileExchange, and it is quite straight-forward to change it to allow working with a stack of RGB images.
The magic part of the function is
imshow(Img(:,:,S))
which displays the slice S of the image Img. We can simply change it to show all 3 channels of image S by changing this to Img(:,:,S,:). The result will be of size 200-by-200-by-1-by-3, while MATLAB expects RGB images to be of size 200-by-200-by-3. Simply squeeze this image to get the correct dimension. This results in:
imshow(squeeze(Img(:,:,S,:))
So to show RGB images, do a search-and-replace inside the function imshow3D, to replace all occurrences of Img(:,:,S) with squeeze(Img(:,:,S,:)) and it works!

Matlab syntax when importing an image from folder

I don't quite understand what line 5 of the following code is doing.
First 4 lines are importing the image from the folder and then storing it in "image1". Then on line 5 i dont get what is being done.
numFolder=fullfile('NumberZero/','Zero/');
for i=1:10;
numName=sprintf('%d.bmp',i);
image1=imread([numFolder, numName]);
im1(:,:,i)=image1; % what is this line doing?
end
That loop is simply loading all of the image data into a variable called im1. The dimensions of this variable are going to be [nRows, nColumns, nImages]. This assumes that the images coming in are actually grayscale rather than RGB (third dimension == 1)
Once this is loaded in, you can then access the different images via the folling approach.
first_image = im1(:,:,1);
second_image = im1(:,:,2);
As a side note, it is recommended to not use i as a loop index.
I posted this question on the "MATLAB Central" Q&A and "Image Analyst" answered my question very nicely.
The line
im1(:,:,i)=image1;
takes a 2D image called image1 and sticks it into the i'th slice (plane) of a 3D image called im1. If im1 already has i slices, then it just overwrites the i'th slice. If im1 does not yet have i slices, then this code will append a slice to grow the 3D image in the "Z" direction. So it's turning 2D images stored on your disk into a 3D image. The images1's must be grayscale for this code to work.

Get matrix from plot and subplot

I already had some figure that I saved before, Like this:
Now after some days, I need the original size of these images for copy these in my paper. I want to extract the main matrix of these three image for save these again with imwrite function.
I searched this problem on the internet but the people says I have to use getframe and frame2im functions. But how? I want the original matrix. Can anyone tell me how to extract the main matrix from the figured image in matlab??
Try using the following code:
imgs = findobj(gcf,'Type','image');
images = cell(1,numel(imgs));
for i = 1:numel(imgs)
images = get(imgs(i),'CData');
end
The image matrices should now be stored in the separate cells of images.

Matlab: How can I get an image handle for a matrix to be used in createMask?

I'm working with netCDF matrices representing satellite imagery. I'm trying to make a binary mask so I can analyze ROIs within the matrix. I've made an imellipse to use as the mask.
Now, the function createMask requires an image handle for the underlying data. How can I get an image handle for my data matrix? I've displayed in as a contourf plot.
The createMask() function works without an image handle as well. To get the binary mask just do like this:
imshow(Img,[]);
e = imellipse();
mask = createMask(e);
If you want to do it using an image handle, you can create an image handle by doing:
h_img = imshow(Img,[]);
You can then use this handle in the createMask() function. (But it is not really neccesary)