shenzhi123 发表于 2007-5-15 18:03

矩阵合成图像问题

我定义的想把r,g,b矩阵合成真彩图象的函数,可是出现了以下问题,想请教一下该怎么改才好啊?
x,y为维数. r,g,b为小波分解的结果,谢谢各位!
function Yt=RGBturecolor(r,g,b,x,y)
Yt=zeros(x,y,3);
YtR=(wcodemat(r,256)-1)/255;
YtG=(wcodemat(g,256)-1)/255;
YtB=(wcodemat(b,256)-1)/255;
for i=1:x
    for j=1:y
      Yt(i,j,1)=YtR(i,j);
      Yt(i,j,2)=YtG(i,j);
      Yt(i,j,2)=YtB(i,j);
    end
end
出现的错误是:Attempted to access YtR(1,149); index out of bounds because size(YtR)=.
Error in ==> RGBtruecolor at 11
      Yt(i,j,1)=YtR(i,j);
Error in ==> xiaobo at 16
ca1=RGBtruecolor(caR1,caG1,caB1,s1(1,1),s1(1,2));

这个是这个函数的原因还是我主函数的原因呢?
我的主函数就是用这个语句调用了一下而已啊ca1=RGBtruecolor(caR1,caG1,caB1,s1(1,1),s1(1,2));

eight 发表于 2007-5-15 20:02

原帖由 shenzhi123 于 2007-5-15 18:03 发表 http://www.chinavib.com/forum/images/common/back.gif
我定义的想把r,g,b矩阵合成真彩图象的函数,可是出现了以下问题,想请教一下该怎么改才好啊?
x,y为维数. r,g,b为小波分解的结果,谢谢各位!
function Yt=RGBturecolor(r,g,b,x,y)
Yt=zeros(x,y,3);
YtR=(wco ...


数组越界问题,先设置断点,后用主函数运行一次,调试一下就可以了

shenzhi123 发表于 2007-5-15 20:09

请问断点怎么设置啊?应该怎么改才好呢?
我觉得好象(1,149)和搭不上,可是不知道怎么改,可以再详细点吗?
是在这个程序里吗?还是要在主函数里?
用不用把主函数贴上来?

eight 发表于 2007-5-15 20:12

原帖由 shenzhi123 于 2007-5-15 20:09 发表 http://www.chinavib.com/forum/images/common/back.gif
请问断点怎么设置啊?应该怎么改才好呢?
我觉得好象(1,149)和搭不上,可是不知道怎么改,可以再详细点吗?
是在这个程序里吗?还是要在主函数里?
用不用把主函数贴上来?

这种问题最好还是自己修改为好,至于调试,每个编程软件都一定有的,因为程序不可能一次编写成功,所以提供这个测试手段。在matlab中,编好程序,设置断点(菜单 Debug 有 Set breakpoint),运行程序(菜单 Debug 有 Run 或 Save & Run)。

建议多看看基础书,还有本版 置顶贴:聚宝盆 中提到的精华贴

shenzhi123 发表于 2007-5-15 20:21

恩,好的,谢谢啊,那我再看看,
再请教个问题,这个是另一个程序的后半部分
%三级小波分解及显示
=wavedec2(I,3,'db2');
ca3=appcoef2(c,s,'db2',3);
ch3=detcoef2('h',c,s,3);
cv3=detcoef2('v',c,s,3);
cd3=detcoef2('d',c,s,3);
ch2=detcoef2('h',c,s,2);
cv2=detcoef2('v',c,s,2);
cd2=detcoef2('d',c,s,2);
ch1=detcoef2('h',c,s,1);
cv1=detcoef2('v',c,s,1);
cd1=detcoef2('d',c,s,1);
A2=;
%显示分解结果
k=s(2,1)*2-s(3,1);
ch2=padarray(ch2,,1,'post');
cv2=padarray(cv2,,1,'post');
cd2=padarray(cd2,,1,'post');
A1=;
k=s(2,1)*4-s(4,1);
ch1=padarray(ch1,,1,'post');
cv1=padarray(cv1,,1,'post');
cd1=padarray(cd1,,1,'post');
A=;
min=min(A(:));
max=max(A(:));
subplot(122);imshow(A,);

程序的前面一直运行的很好,到了倒数第3行出现了错误
??? Subscript indices must either be real positive integers or logicals.

Error in ==> xiaobofenjie23 at 51
min=min(A(:));
是这个错误,前半部分程序和这个相近,就是二级分解和显示,也有min=min(A(:));这个语句,
但是没错误,请问这个是怎么回事啊,我调试好久了,都没明白,:@(

shenzhi123 发表于 2007-5-15 20:23

我电脑最近有点不好使,中过毒,我想请教下,是我电脑的问题还是程序的问题啊?

eight 发表于 2007-5-15 21:44

原帖由 shenzhi123 于 2007-5-15 20:21 发表 http://www.chinavib.com/forum/images/common/back.gif
恩,好的,谢谢啊,那我再看看,
再请教个问题,这个是另一个程序的后半部分
%三级小波分解及显示
=wavedec2(I,3,'db2');
ca3=appcoef2(c,s,'db2',3);
ch3=detcoef2('h',c,s,3);
cv3=detcoef2('v',c,s ...

改为:
myMin = min(A(:));
试试
不要使用 matlab 的函数名作为变量

shenzhi123 发表于 2007-5-15 22:02

谢谢啊,可是还是错误
??? Subscript indices must either be real positive integers or logicals.

Error in ==> xiaobofenjie23 at 51
myMin = min(A(:));

eight 发表于 2007-5-15 22:08

原帖由 shenzhi123 于 2007-5-15 22:02 发表 http://www.chinavib.com/forum/images/common/back.gif
谢谢啊,可是还是错误
??? Subscript indices must either be real positive integers or logicals.

Error in ==> xiaobofenjie23 at 51
myMin = min(A(:));


贴一下你的 A 矩阵

shenzhi123 发表于 2007-5-15 22:22

clear all
I=imread('CIMG1037.JPG');
I=rgb2gray(I);
%二级小波
=wavedec2(I,2,'db2');
ca2=appcoef2(c,s,'db2',2);
ch2=detcoef2('h',c,s,2);
cv2=detcoef2('v',c,s,2);
cd2=detcoef2('d',c,s,2);
ch1=detcoef2('h',c,s,1);
cv1=detcoef2('v',c,s,1);
cd1=detcoef2('d',c,s,1);
A1=;
k=s(2,1)*2-s(3,1);
ch1=padarray(ch1,,1,'post');
cv1=padarray(cv1,,1,'post');
cd1=padarray(cd1,,1,'post');
A=;
min=min(A(:));
max=max(A(:));
subplot(121);imshow(A,);
%三级小波
=wavedec2(I,3,'db2');
ca3=appcoef2(c,s,'db2',3);
ch3=detcoef2('h',c,s,3);
cv3=detcoef2('v',c,s,3);
cd3=detcoef2('d',c,s,3);
ch2=detcoef2('h',c,s,2);
cv2=detcoef2('v',c,s,2);
cd2=detcoef2('d',c,s,2);
ch1=detcoef2('h',c,s,1);
cv1=detcoef2('v',c,s,1);
cd1=detcoef2('d',c,s,1);
A2=;
%显示分解结果
k=s(2,1)*2-s(3,1);
ch2=padarray(ch2,,1,'post');
cv2=padarray(cv2,,1,'post');
cd2=padarray(cd2,,1,'post');
A1=;
k=s(2,1)*4-s(4,1);
ch1=padarray(ch1,,1,'post');
cv1=padarray(cv1,,1,'post');
cd1=padarray(cd1,,1,'post');
A=;
myMin = min(A(:));
myMax = max(A(:));
subplot(122);imshow(A,);

shenzhi123 发表于 2007-5-15 22:22

谢谢啊

eight 发表于 2007-5-15 22:26

原帖由 shenzhi123 于 2007-5-15 22:22 发表 http://www.chinavib.com/forum/images/common/back.gif
谢谢啊

我要的是运行时你的 A 矩阵的值

shenzhi123 发表于 2007-5-15 22:31

不好意思,理解错误
A矩阵的值好多,有正有负,这是截取其中的一段,这样可以吗?不行的话,我再从发
-0.0090    0.0172   -0.0026    0.0019   -0.0023   -0.0026    0.0014   -0.0013
   -0.0041   -0.0208   -0.0030   -0.0036    0.0009    0.0043    0.0006   -0.0075
    0.0006   -0.0189   -0.0053   -0.0011    0.0035    0.0016    0.0070    0.0016
    0.0060    0.0081   -0.0020    0.0048    0.0007    0.0014   -0.0010    0.0018
    0.0023    0.0001    0.0066   -0.0083   -0.0060   -0.0020    0.0010    0.0028
   -0.0010    0.0011    0.0008   -0.0078   -0.0036   -0.0126    0.0012    0.0055
   -0.0043   -0.0007   -0.0026    0.0100    0.0032    0.0149   -0.0191   -0.0101
    0.0039   -0.0155    0.0079   -0.0013   -0.0006    0.0063   -0.0024   -0.0038
   -0.0014   -0.0052    0.0040    0.0049   -0.0109    0.0065    0.0047   -0.0012
   -0.0099   -0.0011   -0.0086   -0.0040   -0.0020   -0.0052   -0.0060    0.0061
   -0.0003    0.0083   -0.0172    0.0295    0.0088   -0.0125    0.0058   -0.0078
    0.0126   -0.0012   -0.0067   -0.0092   -0.0045   -0.0140    0.0015    0.0017
    0.0005    0.0070    0.0080    0.0076    0.0036   -0.0014    0.0047    0.0083
    0.0094    0.0011    0.0022   -0.0061   -0.0031    0.0053    0.0026   -0.0145
   -0.0039    0.0035    0.0056    0.0038    0.0039    0.0020   -0.0131   -0.0018
   -0.0117   -0.0015   -0.0035   -0.0132   -0.0011    0.0037    0.0092    0.0045
   -0.0050    0.0015   -0.0023    0.0131    0.0100    0.0054    0.0088   -0.0006
    0.0024   -0.0137   -0.0228   -0.0130   -0.0099   -0.0029    0.0003    0.0

shenzhi123 发表于 2007-5-15 22:43

Cannot display variables with more than 524288 elements.
这个是在workspace中双击A打开时显示的文字,没显示矩阵
当我把图象改小后,改成800*252的以后,A就没有这句话了,
但运行上面的程序出现了这个错误
??? Error using ==> vertcat
All rows in the bracketed expression must have the same
number of columns.

Error in ==> xiaobofenjie23 at 45
A1=;

eight 发表于 2007-5-15 23:11

原帖由 shenzhi123 于 2007-5-15 22:43 发表 http://www.chinavib.com/forum/images/common/back.gif
Cannot display variables with more than 524288 elements.
这个是在workspace中双击A打开时显示的文字,没显示矩阵


这个错误是没有关系的,可以不管

至于你的问题,一时这个错误,一时那个错误,我看不出来,建议先别急,看看基础书,多了解矩阵运算
页: [1] 2
查看完整版本: 矩阵合成图像问题