MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   取消合并图像 (https://www.labfans.com/bbs/showthread.php?t=26603)

poster 2019-12-14 20:13

取消合并图像
 
目的是将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);[LIST=1][*]这导致错误

???下标索引必须是实数正整数或逻辑值。

错误==> Combined_img在11 E1 = E(:,img1,img2);
[/LIST]请帮助解决此问题。



[B]回答:[/B]

该错误正是它所说的:索引必须是整数或逻辑。当您尝试使用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

[url=https://stackoverflow.com/questions/5315677]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 22:45

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.