This question already has answers here:
Extract arbitrarily rotated plane of data from 3D array as 2D array
(2 answers)
Closed 8 years ago.
I have a 3D stack of bwlabeln'ed data (128 by 128 by 128). Is there a way to cut a slice through it (as in MATLAB slice(...)) and save the resulting image to a matrix?
Thanks in advance!
the function that may be of use is:
http://www.mathworks.com/matlabcentral/fileexchange/32032-extract-slice-from-volume
for other solutions, see:
Extract arbitrarily rotated plane of data from 3D array as 2D array
What kind of slice? Along one dimension e.g. z=5 you can use M(:,:,5). For diagonal slices you have to use some advanced method (interpolation).
Related
This question already has answers here:
Turn a MATLAB plot into image
(2 answers)
Save a plot in Matlab as a matrix [duplicate]
(2 answers)
How can I save an altered image in MATLAB?
(8 answers)
How do I save a plotted image and maintain the original image size in MATLAB?
(1 answer)
Closed 5 years ago.
Suppose you have one image.
You plot this image.
After that, you plot a green tracing on top of that image.
You make this plot easily using the plot function.
After this initial plot, you add a second tracing on top of the same image.
Therefore you have a figure with two plots just like in this image.
How can I store the result of this multiple plots to one variable without saving to file and then reading the final result?
I can do this if I print and then read the image but I want the same result without having the additional step of saving to file.
Any clue?
Example code and figure:
imshow(a)
hold on
plot(centroidsFiltered(:,2),centroidsFiltered(:,1),'.g','LineWidth',0.5)
plot(int32(centroidsFiltered(i,2)), int32(centroidsFiltered(i,1)), '.g', 'MarkerSize',20)
The data resulting from the plot is this figure.
How can I store all the resulting information to one variable?
Data can be downloaded here: https://expirebox.com/download/c95e9a0e5ac5530729f6960679ec9733.html
CLARIFICATION
What I want as an output variable from this plot is the original image matrix, with the update in the matrix positions where the green line and the green marker is perceptible.
You could try using getframe. See Documentation
imshow(a)
hold on
plot(centroidsFiltered(:,2),centroidsFiltered(:,1),'.g','LineWidth',0.5)
plot(int32(centroidsFiltered(i,2)), int32(centroidsFiltered(i,1)), '.g', 'MarkerSize',20)
b = getframe(gca);
To recreate the plot:
figure;
imshow(b.cdata)
Note: That the size of b.cdata and a will not be exactly the same. Since this is a screen grab of the axis b will most likely have some extra pixels around the border. However, with a careful setting of units to pixels and using the optional rect input to getframe you may be able to get the output dimensions correct.
This question already has answers here:
Find contour of 2D object in image in matlab
(1 answer)
Contour detection in MATLAB
(1 answer)
MATLAB - Find contour of a binary bit map?
(3 answers)
Compute contour of a binary image using matlab
(3 answers)
Closed 5 years ago.
I'm working to classify objects as human or non-human. My research focuses on the shape detection. I tried to use the function edge in MATLAB but I do not know how to find the boundary edge for the head, neck and shoulders only for a human object from an image. In another words I want to ignore the internal edges; I just want the boundary edge.
Can anyone help me in this?
i want to get this part only from the human object
This question already has answers here:
Matching images with different orientations and scales in MATLAB
(4 answers)
Closed 7 years ago.
After bounding natural images with textboxes (green), I want to apply a homography matrix (perspective correction) to project the green area to a rectangle.
Please refer to the link for the image mentioned above
http://i.stack.imgur.com/nhe4S.jpg
How can I implement the code / call the code in
http://www.mathworks.com/matlabcentral/answers/26141-homography-matrix
Alternatively, any other possibilities of other suitable algorithms?
I can provide you with the coordinates of the bounding box, obtained with
img=imread('perspective.jpg');
imshow(img); ginput(4)
and the coordinates of the quadrangle is
ans =
23.1597 25.0459
22.0220 55.9541
164.2375 61.6427
165.3752 30.1657
You can compute the homography transformation between the two bounding boxes using the fitgeotrans function. You can then apply the resulting transformation to the image using imwarp.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
matlab: scatter plots with high number of datapoints
I have 3 vectors of 315,000 elements each. X,Y, and Z. X & Y are coordinates and Z is a value. I must plot the coordinates as points in a 2D graph, the Z is a color indicator at each coordinate of X and Y. I've tried the "scatter" command, but it extremely slow. Would anybody suggest a better way?
thanks!
Depending on what kind of color map you are looking for, you can try something like
zmin=min(Z);
zmax=max(Z);
map=colormap;
color_steps=size(map,1);
hold on
for i=1:color_steps
ind=find(Z<zmin+i*(zmax-zmin)/color_steps & Z>=zmin+(i-1)*(zmax-zmin)/color_steps);
plot(X(ind),Y(ind),'o','Color',map(i,:));
end
The finding is a little expensive but it seems to be quicker than scatter. I'm sure you could optimize this further.
Try cline from MATLAB file exchange here. It looks like it does exactly what you want.
Your code is slow because of the large size of the vectors, not because of the SCATTER function. Try breaking them down into vectors of smaller size (say, 10 elements each) and putting each vector into a cell of a cell array. Then loop through the cell array and scatter each smaller vector individually to avoid loading too much into the memory.
hold on
for i=1:numel(XcoordCellArray):
scatter(XcoordCellArray{i},YcoordCellArray{i},S,ZcoordCellArray{i})
end
This question already has answers here:
Plotting 3-D Matrix *values* in MATLAB
(2 answers)
Closed 7 years ago.
Ive created a 3d matrix in MATLAB. The values of the matrix are the velocity at that point in a rectangular section. I would like a plot with colours showing the values at each position, is this possible?
Phrasing this another way, I have a matrix of size 100x100x200. Id like a graph that has 100x100x200 points and the colour of each of those points is related to its value.
This question is very similar to this question. You might want to check it out.
UPDATE:
Suppose you have a 3D matrix A:
A = rand(100,100,200);
You want to plot each entry of A mapped to a color at its 3D coordinates. First generate the coordinates:
[x,y,z] = meshgrid(1:100,1:100,1:200);
Now you are ready to use scatter3:
scatter3(x(:),y(:),z(:),5,A(:))
Here the : indexing vectorizes the coordinates column-wise.
Hope this helps.