使用mrdivide时出错

时间:2013-03-02 14:13:54

标签: matlab

我从互联网上找到了这段代码,在运行代码时输出显示正确但我仍然遇到一个错误,这在使用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:使用matlab链接java我使用了一个开源的Matlab Control谷歌代码,从命令行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();
}
}

0 个答案:

没有答案