Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
目的是将3个相等大小的图像(512 * 512 * 3)合并为结果图像E,其大小为r = 1536 c = 512 d = 3
img1=imread('pic1.jpg'); img2=imread('pic2.jpg'); img3=imread('pic3.jpg'); figure; E = [img1; img2; img3]; imshow(E); figure; subplot(1,3,1); E1 = E(:,img1,img2); imshow(E1); E2=E(img1,:,img3); sublot(1,3,2); imshow(E2); E3=E(img1,img2,:); sublot(1,3,3); imshow(E3);
回答: 该错误正是它所说的:索引必须是整数或逻辑。当您尝试使用img1进行索引时,很可能包含非整数,从而引发错误。这是您应该做的: E=[img1; img2; img3];%#combine the images E1=E(1:512,:,:); E2=E(513:1024,:,:); E3=E(1025:end,:,:); 您也可以更优雅地进行 imgDim=size(img1,1);%# since they're all equal dimensions, we'll need just one. imgCell=mat2cell(E,[imgDim,imgDim,imgDim],imgDim,3);%# create a cell [E1, E2, E3]=deal(imgCell{:});%#distribute contents of cell 更多&回答... |
![]() |
![]() |