How to construct a big image from many images

2 Ansichten (letzte 30 Tage)
amir nemat
amir nemat am 12 Sep. 2017
Beantwortet: Image Analyst am 12 Sep. 2017
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?

Antworten (2)

Rik
Rik am 12 Sep. 2017
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 Kommentare
amir nemat
amir nemat am 12 Sep. 2017
Thanks for your answer. My intention is make a big image from many different images. I think repmat and imread cannot work due to require more memory. Can I use file for image?
Rik
Rik am 12 Sep. 2017
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.

Melden Sie sich an, um zu kommentieren.


Image Analyst
Image Analyst am 12 Sep. 2017
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().

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by