stitching an image together from others
Show older comments
Hi,
I am calling two for loops to load a set of map png images into matlab. I then want to stitch them together. 5x5 at the moment.
I was previously setting each image loaded to, img1 img2 etc, and then stitching them together using
str1 = sprintf('F:\\Mapping\\%g\\%g,x,y);
A1 = exist(str1);
if A1 == 2;
img1 = imread(str1);
else
img1 = imread('F:\Mapping\No_File.png')l
end
and then stitching them all together as so:
map = [img1,img2,img3,img4,img5;img6... etc];
In order to simplify, I would like to run a for loop and do the following:
for m = x-2:1:x+2
for n = y - 2:1:y+2
str = sprintf('F:\\Mapping\\%s\\%g\\%g\\%g\\%g\\%g.png',mstring,z,xi,m,yi,n);
A = exist(str);
if A == 2;
img = imread(str);
else
img = imread('F:\Mapping\No_File.jpg');
end
%%%%%%%%%%%%%%%
end
end
except I'm not sure now how to write the map = [img1,img2... etc part as obviously I am changing the value of img each loop.
How would I write the img to the appropriate part of the map image? Is there a way?
I've tried:
stitchxstart = (m-x+2)*256 + 1;
stitchxend = (m+1-x+2)*256;
stitchystart = (n-y+2)*256 + 1;
stitchyend = (n+1-y+2)*256;
and then write as:
map(stitchxstart:stitchxend,stitchystart:stitchyend,:) = img;
as I know the outcome will be a 1280*1280*3... but it obviously doesn't work... not quite sure how to write it to the map variable in the correct manner.
Thanks in advance....
Accepted Answer
More Answers (1)
John
on 22 Jun 2012
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!