Info
此问题已关闭。 请重新打开它进行编辑或回答。
Matrix dimensions must agree. Error in pre (line 146) inv_trans_img(:,l)=v{m-1}.*trans_img(:,l);..............I am getting this error if anybody would help me to sortout this then it will be a goodhelp
1 次查看(过去 30 天)
显示 更早的评论
if true
% code
endclear all
close all
clc
[filename, pathname] = uigetfile('*.bmp', 'Pick an M-file');
if isequal(filename,0) || isequal(pathname,0)
warndlg('Image is not selected');
else
a=imread(filename);
figure(1)
imshow(a)
a=rgb2gray(a);
figure(2);
imshow(a)
title('converted image from rgb to gray')
a=imresize(a,[512,512]);
figure(3)
imshow(a,[])
title('cover image')
a=im2double(a);
%imshow(a);
end
[filename, pathname] = uigetfile('*.bmp', 'Pick an M-file');
if isequal(filename,0) || isequal(pathname,0)
warndlg('Image is not selected');
else
secret=imread(filename);
%imshow(secret);
figure(4)
imshow(secret,[])
title('Watermark Image')
end
m=1;
% k=30;
for i=1:8:256
for j=1:8:256
for x=0:7
for y=0:7
img(x+1,y+1)=a(i+x,j+y);
end
end
k=0;
for l=1:8
img_expect{k+1}=img(:,l)*img(:,l)';
k=k+1;
end
imgexp=zeros(8:8);
for l=1:8
imgexp=imgexp+(1/8)*img_expect{l};%expectation of E[xx']
end
img_mean=zeros(8,1);
for l=1:8
img_mean=img_mean+(1/8)*img(:,l);
end
img_mean_trans=img_mean*img_mean';
img_covariance=imgexp - img_mean_trans;
[v{m},d{m}]=eig(img_covariance);
temp=v{m};
m=m+1;
for l=1:8
v{m-1}(:,l)=temp(:,8-(l-1));
end
for l=1:8
trans_img1(:,l)=v{m-1}*img(:,l);
end
for x=0:7
for y=0:7
transformed_img(i+x,j+y)=trans_img1(x+1,y+1);
end
end
end
end
% transformed image is assigned to cover_object
cover_object=double(transformed_img);
Mc=size(cover_object,1); %Height
Nc=size(cover_object,2); %Width
% determine maximum message size based on cover object, and blocksize
max_message=Mc*Nc;
% read in the message image
message=double(secret);
Mm=size(message,1); %Height
Nm=size(message,2); %Width
% reshape the message to a vector
message=round(reshape(message,Mm*Nm,1)./256);
% check that the message isn't too large for cover
if (length(message) > max_message)
error('Message too large to fit in Cover Object')
end
% pad the message out to the maximum message size with ones's
message_vector=ones(1,max_message);
message_vector(1:length(message))=message;
% generate shell of watermarked image
watermarked_image=cover_object;
% read in key for PN generator
file_name='_key.bmp';
% key=double(imread(file_name))./256;
% reset MATLAB's PN generator to state "key"
rand('state',35);
% generate PN sequence
pn_sequence_zero=round(2*(rand(1,sum(sum(512)))-0.5));
pn_sequence_one=round(2*(rand(1,sum(sum(512)))-0.5));
% process the image in blocks
%x=1;
%y=1;
for kk = 1:length(message_vector)
% transform block using DCT
dct_block=(cover_object(1:256,1:256));
% if message bit contains zero then embed pn_sequence_zero into the mid-band
% componants of the dct_block
ll=1;
if (message_vector(kk)==0)
for ii=1:256
for jj=1:256
if (dct_block(jj,ii)==1)
dct_block(jj,ii)=(dct_block(jj,ii))+k*pn_sequence_zero(ll);
ll=ll+1;
end
end
end
else
for ii=1:256
for jj=1:256
if (dct_block(jj,ii)==1)
dct_block(jj,ii)=(dct_block(jj,ii))+k*pn_sequence_zero(ll);
ll=ll+1;
end
end
end
end
% transform block back into spatial domain
% watermarked_image(1:256,1:256)=((dct_block));
% move on to next block. At and of row move to next row
% % if (x+512) >= Nc
% x=1;
% y=y+512;
% else
% x=x+512;
% end
end
mask=[1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1 ];
trans_img=dct_block'.*1;
for l=1:256
inv_trans_img(:,l)=v{m-1}.*trans_img(:,l);
end
for x=0:3
for y=0:3
inv_transformed_img(i+x,j+y)=inv_trans_img(x+1,y+1);
imwrite(uint8(inv_transformed_img),'Lena_wtermarked_image.bmp','bmp');
end
end
figure(5)
imshow(transformed_img);
title('transformed image')
figure(6)
imshow(inv_transformed_img);
title('inverse transformed image')
% imwrite(uint8(inv_transformed_img),'Lena_wtermarked_image.bmp','bmp');
figure(7)
LWI=imread('Lena_wtermarked_image.bmp');
imshow(LWI);
title('Watermarked Image')
4 个评论
Walter Roberson
2018-10-9
I doubt that anyone will read the code thoroughly and work through the undocumented mathematical operations and mentally work backwards to figure out what a useful set of operations would be instead and tell you the appropriate code, all without even having your test image.
回答(0 个)
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!