[code]im = im2double(imread('rice.png'));
[X Y]= meshgrid(1:size(im,1),1:size(im,2));
surf(zeros(size(im)),X,Y,im,'EdgeColor','none');[/code]
when i run this script it worked me fine but when i tried to change the image to RGB image it gives me this 2 errors
??? Error using ==> surf at 78 Data dimensions must agree.
Error in ==> CoOrdinating at 6 surf(zeros(size(im)),X,Y,im,'EdgeColor','none');
i tried to convert the image to grayscale but it didn't work with me and gave me the same errors
any help ?

댓글 수: 3

Jan
Jan 2011년 5월 14일
Please post, what exactly "when i tried to change the image to RGB" means. If the problem depends on this details, it is worth to show it.
Amr
Amr 2011년 5월 14일
when i used another image which is colored one
Jan
Jan 2011년 5월 14일
Please post the Matlab code. Bugs in the code cannot be found in a text description of the method.

댓글을 달려면 로그인하십시오.

 채택된 답변

Andrew Newell
Andrew Newell 2011년 5월 15일

1 개 추천

Here is a demo that works:
rgb_img = imread('ngc6543a.jpg');
imshow(rgb_img)
I = .2989*rgb_img(:,:,1)...
+.5870*rgb_img(:,:,2)...
+.1140*rgb_img(:,:,3);
figure;
imshow(I)
I = double(I);
[X,Y]= meshgrid(1:size(I,1),1:size(I,2));
figure;
surf(zeros(size(I')),X,Y,I','EdgeColor','none');
colormap('gray')
Probably you didn't take the transpose of I in the surf command. I don't know why you need to do this, but you do.

댓글 수: 2

Walter Roberson
Walter Roberson 2011년 5월 15일
Taking the transpose or not would be the difference between using meshgrid() or using ndgrid().
>> size(meshgrid(1:2,1:3))
ans =
3 2
>> size(ndgrid(1:2,1:3))
ans =
2 3
Andrew Newell
Andrew Newell 2011년 5월 15일
Good point. I had a feeling I'd be hearing from you!

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Andrew Newell
Andrew Newell 2011년 5월 14일

0 개 추천

If you enter the command
I = imread('rice.png');
you get a matrix. If you enter
I = imread('ngc6543a.jpg');
you get a 3D array with one page for each of the R, G and B components of the color. This does not have the same dimensions as the matrices X and Y.

댓글 수: 2

Amr
Amr 2011년 5월 14일
i convert it to gray scale and it became matrix like the other X and Y
Walter Roberson
Walter Roberson 2011년 5월 16일
Amr, I am not sure whether you are still having difficulty with this matter?

댓글을 달려면 로그인하십시오.

guj
guj 2011년 5월 15일

0 개 추천

am also stuck in same thing I have samples point of 5:5:85 missing samples ..so i have 17 numbers which i have chosen has missing %.
so my vector is of length 17 by 1
Number of iteration = 500;
number of iteration carried out for reconstruction is 500 but 100 seems to be enough...so i have just zeros after 100 row my matrix is 500 by 17 in my error)matrix
I am using [X,Y]=meshgrid(iteration,missing sample) surf(X,Y,errormatrix(1:100,:))
But i am getting error...
whole objective is to show 3d graph having iteration on one axis, missing % of samples on other axis and error on the third one
This is what i am doing
[X,Y]=meshgrid(x,y) x=1 by 17 (decimation factors) y=1 by 100 (number of iteration)
errormatrix=[100 by 17] whch shows error during 100 iteration for each decimation %.
now surf(X',Y,errormatrix(1:100,:))
Error dimension at 78

댓글 수: 1

Andrew Newell
Andrew Newell 2011년 5월 15일
This is not an answer to this question and shouldn't be here. If my answer above doesn't solve your problem, you could make a new question. Please delete this one.

댓글을 달려면 로그인하십시오.

Alexandra Roxana
Alexandra Roxana 2021년 7월 18일

0 개 추천

Hello! I'm having the same problem. I want to plot the results from the following code:
clc
clear all
alpha = 2;
L=50;
dx = 1;
dt = (dx^2)/(4*alpha);
gamma = (alpha*dt)/(dx^2);
itert = 1000;
u=zeros(itert,L,L);
uinit = 0;
utop=1;
uleft=0;
ubottom=0;
uright=0;
%Boundary conditions
u(:,L,:)=utop;
u(:,:,1)=uleft;
u(:,1,1)=ubottom;
u(:,:,L)=uright;
for k=1:itert-1
for i=2:L-1
for j=2:L-1
u(k+1,i,j) = gamma*(u(k,i+1,j) + u(k,i-1,j) + ...
u(k,i,j+1) + u(k,i,j-1) - 4*u(k,i,j)) + u(k,i,j);
end
end
end
%display(u)
[x,y]=meshgrid(0:.01:pi);
mesh(x,y,u)

댓글 수: 8

Torsten
Torsten 2021년 7월 18일
The region where you solved Poisson's equation is [0:50] x [0:50] with step 1, not something with pi.
Further
u(:,1,:) = ubottom,
not
u(:,1,1) = ubottom.
Modified it with
[x,y]=meshgrid(0:0.1:50);
mesh(x,y,u)
Still doesn't work.
Torsten
Torsten 2021년 7월 18일
[X,Y] = meshgrid(1:50,1:50);
U = u(1,:,:);
U = U(:);
surf(X,Y,U)
But I'm unsure whether the order of U corresponds to the order of the (X,Y) pairs.
Alexandra Roxana
Alexandra Roxana 2021년 7월 18일
Now it says that Z must be a matrix, not a scalar or vector.
Torsten
Torsten 2021년 7월 18일
Then delete the line
U = U(:)
Alexandra Roxana
Alexandra Roxana 2021년 7월 18일
I already did. No result. X,Y = 50x50 double, U = 1x50x50 double, u = 100x50x50 double, I think it has to do with the dimensions.
Torsten
Torsten 2021년 7월 18일
Then replace
U = u(1,:,:)
by
U(:,:) = u(1,:,:)
Alexandra Roxana
Alexandra Roxana 2021년 7월 18일
Now it works! Thank you! I guess I have to work on the code because the graph isn't quite what I expected it to be.

댓글을 달려면 로그인하십시오.

카테고리

태그

아직 태그를 입력하지 않았습니다.

질문:

Amr
2011년 5월 14일

댓글:

2021년 7월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by