The objective is to combine 3 equal sized images(512*512*3) into a resultant image E whose size is 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);
-
This results into error
??? Subscript indices must either be real positive integers or logicals.
Error in ==> combined_img at 11
E1 = E(:,img1,img2);
Please help to resolve this .
The error is exactly what it says it is: the indices must be integers or logicals. When you try to index using
img1, it’s likely that it contains non-integers, which throws the error. Here’s what you should do:You can also do it more elegantly as