0

我从互联网上找到了这段代码,在运行代码时输出正确显示,但我仍然收到一个错误,这在将代码与 java 一起使用时会产生问题。

这是代码:

file_name='lena.bmp'; 
cover_object=double(imread(file_name)); 
mc=size(cover_object,1); 
nc=size(cover_object,2); 
file_name='dmg2.bmp'; 
message=double(imread(file_name)); 
mm=size(message,1); 
nm=size(message,2); 
[ca,ch,cv,cd]=dwt2(cover_object,'haar'); 
ca1=ca; 
qiangdu=1; 
for i=1:nm 
    for j=1:nm 
        if(message(i,j)==0) 
            ca1(i,j)=ca(i,j)+qiangdu; 
        end 
    end 
end 
watermarked_image=idwt2(ca1,ch,cv,cd,'haar'); 
watermarked_image_round=round(watermarked_image); 
watermarked_image_uint8=uint8(watermarked_image_round); 
imshow(watermarked_image_uint8);  
figure(2) 
imshow(watermarked_image_uint8,[]) 
title('watermarked image') 
imwrite(watermarked_image_uint8,'dwt_watermarked.bmp','bmp'); 
xsz=mc*nc*max(max(cover_object.^2))/sum(sum((cover_objectwatermarked_image_round).^2)); 
psnr=10*log10(xsz);

这是我得到的错误:

Error using ==> mrdivide
Input arguments must be 2-D.

Error in ==> emb at 33
xsz=mc*nc*max(max(cover_object.^2))/sum(sum((cover_object-watermarked_image_round).^2)); 

编辑 1:为了将 java 与 matlab 链接,我使用了一个开源的 Matlab Control google 代码,从命令行 javac Dwtembed.java 运行此代码。如果你复制粘贴下面的代码并检查一下,你就会明白我实际上想要做什么

import matlabcontrol.*;
class Dwtembed
{
public static void main(String[] args) throws MatlabConnectionException, MatlabInvocationException
{
        //Create a proxy, which we will use to control MATLAB
        MatlabProxyFactory factory = new MatlabProxyFactory();
        MatlabProxy proxy = factory.getProxy();

        proxy.eval("file_name='lena.bmp';"); 
    proxy.eval("cover_object=double(imread(file_name));"); 
    proxy.eval("mc=size(cover_object,1);"); 
    proxy.eval("nc=size(cover_object,2);"); 
    proxy.eval("file_name='dmg2.bmp';"); 
    proxy.eval("message=double(imread(file_name));"); 
    proxy.eval("mm=size(message,1);"); 
    proxy.eval("nm=size(message,2);"); 
    proxy.eval("[ca,ch,cv,cd]=dwt2(cover_object,'haar');"); 
    proxy.eval("ca1=ca;"); 

    proxy.eval("qiangdu=1;"); 

    proxy.eval("for i=1:nm"); 
            proxy.eval("for j=1:nm"); 
                proxy.eval("if(message(i,j)==0)"); 
                    proxy.eval("ca1(i,j)=ca(i,j)+qiangdu;"); 
                proxy.eval("end"); 
            proxy.eval("end"); 
    proxy.eval("end"); 

    proxy.eval("watermarked_image=idwt2(ca1,ch,cv,cd,'haar');"); 
    proxy.eval("watermarked_image_round=round(watermarked_image);"); 
    proxy.eval("watermarked_image_uint8=uint8(watermarked_image_round);"); 
    proxy.eval("imshow(watermarked_image_uint8);"); 

    proxy.eval("figure(2);");
    proxy.eval("imshow(watermarked_image_uint8,[]);");
    proxy.eval("title('watermarked image');");
    proxy.eval("imwrite(watermarked_image_uint8,'dwt_watermarked.bmp','bmp');"); 
    proxy.eval("xsz=mc*nc*max(max(cover_object.^2))./sum(sum((cover_object-watermarked_image_round).^2));"); 
    proxy.eval("psnr=10*log10(xsz);");



        //Disconnect the proxy from MATLAB
        proxy.disconnect();
}
}
4

0 回答 0