How to construct a big image from many images
2 次查看(过去 30 天)
显示 更早的评论
I am working on google map images. I would like to save more than several thousands images in a big image. I have developed following code:
img=imread('sample.jpg');
[dim1 dim2 dim3]=size(img);
for i=1:1000
for j=1:1000
total((i-1)*dim1+1:i*dim1,(j-1)*dim2+1:j*dim2,:)=img(:,:,:);
end
end
Is it any efficient method to save and display the big image?
0 个评论
回答(2 个)
Rik
2017-9-12
This code replicates your sample picture. If this is the intention, I suspect the implementation of repmat is more efficient:
total=repmat(img,1000,1000,1);
If you want to stitch images together you should move the imread to the inside of the loop. I recommend sprintf to generate the filenames if they have a systematic name based on the position. There may be a better method of concatenating the images, but I think the bottleneck in speed will be in the imread. You should pre-allocate a matrix before the loop to speed it up. This loop will result in a million calls to the code inside, so you need to make sure you're doing the absolute minimum in there.
2 个评论
Rik
2017-9-12
I don't believe it is possible to concatenate images inside a file with Matlab. It might be, but that would depend on the file structure. I think you will need to think about what it is you want, because if you can't read it in one go, you can't process it in one go. So what are you going to do with the big image file once you have it? Maybe you can change the post-processing so you can skip the compilation into a single file.
Image Analyst
2017-9-12
I doubt you're going to be able to have an image consisting of thousands of normal sized (10~20 megapixels) all in memory at once. Ten thousand 10 MP images would create a hundred gigapixel image, or about 3 terabytes of memory. What computer of yours would be able to handle that? So you should look at memmapfile().
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!