matrix Dimension Must Agree

please some suggest me Where I am going wrong, I want to add periodic noise in my Image
if true
tw=imread('twins.tif');
t=rgb2gray(tw);
%Creating Periodic noise
s=size(t);
[x,y]=meshgrid(1:s(1),1:s(2));
p=(sin(x/3+y/5)+1);
t_pn=(im2double(t)+(p/2)/2);
imshow(t),figure,imshow(t_pn);
% code
end

댓글 수: 2

Walter Roberson
Walter Roberson 2013년 3월 10일
Which line is the problem appearing on?
Error using +
Matrix dimensions must agree.
Error in saltpepper (line 14)
t_pn=(im2double(t)+(p/2)/2);

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

 채택된 답변

Wayne King
Wayne King 2013년 3월 10일

0 개 추천

Without more information about your image size, which you don't provide, it's hard to say, but try transposing the p matrix as I've done below:
tw=imread('twins.tif');
t=rgb2gray(tw);
%Creating Periodic noise
s=size(t);
[x,y]=meshgrid(1:s(1),1:s(2));
p=(sin(x/3+y/5)+1)';
t_pn=(im2double(t)+(p/2)/2);

댓글 수: 3

Walter Roberson
Walter Roberson 2013년 3월 10일
Ah, or using ndgrid() instead of meshgrid() and not doing the transpose.
Muhammad Ali Qadar
Muhammad Ali Qadar 2013년 3월 10일
Worked !!!! Thanks a lot, can you Please Tell me how could you figure out this trick.
Wayne King
Wayne King 2013년 3월 10일
Glad it worked, not a trick, I think Walter's comment is instructive here.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by