MATLAB Answers

mesh, intensity image, 3D

33 views (last 30 days)
Jean
Jean on 29 Jun 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 Comments

Walter Roberson
Walter Roberson on 29 Jun 2013
Please show your code.
Jean
Jean on 30 Jun 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.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 29 Jun 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 Comment

Jean
Jean on 30 Jun 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!

Sign in to comment.

More Answers (0)

Sign in to answer this question.