mesh, intensity image, 3D

3 visualizaciones (últimos 30 días)
Jean
Jean el 29 de Jun. de 2013
Hello, I am doing some image processing in which I have imported a video clip and extracted relevant frames. I want to take one of the images (which is in intensity values) and use mesh() or a similar function to create a 3D plot where x and y are the location of the pixels and the z axis is the intensity or pixel value. When I use the mesh() function, I just get a blank 3D plot and 'Warning: Matrix dimensions must agree, not rendering mesh.' What am I doing wrong? any help? Does the intensity spectrum need to be adjusted? How do I make the matrix dimensions 'agree'? Thanks very much for any help.
  2 comentarios
Walter Roberson
Walter Roberson el 29 de Jun. de 2013
Please show your code.
Jean
Jean el 30 de Jun. de 2013
%Create working directory and name workingDir=tempname; mkdir(workingDir); mkdir(workingDir, 'images'); vids1=VideoReader('trimmedshort1_4.mov'); %select frames, extract, convert to intensity for ii=1000:1005 img1=read(vids1,ii); hcsc = vision.ColorSpaceConverter; hcsc.Conversion = 'RGB to intensity'; I_I1 = step(hcsc, img1); I_I2=imcomplement(I_I1); %adjust intensity J1 = imadjust(I_I2,[],[],100);
imwrite(J1,fullfile(workingDir,'images',sprintf('img%d.jpg',ii))); end %sort into proper order imageNames = dir(fullfile(workingDir,'images','*.jpg')); imageNames = {imageNames.name}'; imageStrings = regexp([imageNames{:}],'(\d*)','match'); imageNumbers = str2double(imageStrings);[~,sortedIndices] = sort(imageNumbers); sortedImageNames = imageNames(sortedIndices); disp(sortedImageNames) %write video file outputVideo = VideoWriter('vidout.avi'); outputVideo.FrameRate = vids1.FrameRate; open(outputVideo); for iii = 1:length(sortedImageNames) img = imread(fullfile(workingDir,'images',sortedImageNames{iii})); writeVideo(outputVideo,J1); end
THis is the original script (above) that I use to generate the images. Then, I do something like this to try to get the spacial/intensity 3D plot with one of the image frames:
img = imread(fullfile(workingDir,'images',sortedImageNames{1})); imshow(img) mesh(double(img) which is a bit stringy and unhelpful if coming from an intensity grayscale image (I want the result in colormap jet) I can do surf(double(img) which yields a surface plot all in black, or meshgrid(img) which runs forever and freezes my computer. Any advice? Many thanks.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 29 de Jun. de 2013
Are you constructing your x and y coordinates using meshgrid() ? If you are, use ndgrid() instead.
[x, y] = ndgrid(.....);
mesh(x, y, z)
  1 comentario
Jean
Jean el 30 de Jun. de 2013
Hey guys, thank you, I did eventually get it; had to use mesh(double(...)). I will try this as well to evaluate options. One issue I am still having is the 3D spacial and intensity plot only shows up in colormap jet if the image is already mapped that way. Otherwise, I get a similar plot, but only black for all z levels (so a big black blob). I will post my code in answer to Walter. Thanks again to all!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Colormaps en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by