MATLAB: Matrix Dimension Must Agree

digital image processingMATLAB

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

Best Answer

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);