1

I'm trying to concatenate a list of 1600*900 images as a mosaic but i cannot allocate a Bitmap of (for example) 100k per 100k.

And so i'm lookin for a way to create a bitmap file and write on it in a stream-like way.

How can i do? Thank You.

Mauro Sampietro
  • 2,739
  • 1
  • 24
  • 50
  • 1
    Is it possible to: for each image, scale the image down and only store the scaled down version in memory? I don't think you need the image in full resolution when you create mosaic. – nhahtdh May 26 '12 at 14:38
  • what architecture are you doing this on? – Michael Dautermann May 26 '12 at 14:43
  • A 100k x 100k 24-bit color bitmap would occupy 28 gigabytes of memory. What exactly is the format of your bitmap file that can handle such amount of data? – panda-34 May 26 '12 at 14:48
  • I've already written software that 'mosaics' a main image with scaledown and applies the scaled down image to an area of the main image. Now i'd like to have an image per pixel on the main image. I'm using .Net for practise this out and than i'll go with cuda for nvidia gpu and/or quicksync for intel cpu (or a mix or that). – Mauro Sampietro May 27 '12 at 14:48

1 Answers1

0

Although the exact practical value of a 100k-by-100k image is yet to be known, the solution might be:

  1. Create a list of offsets of the source images in the resulting W-by-H mosaic. Some calculations here: 100k-by-100k image can hold approximately 50-by-100 images (5k only, a reasonable number). So you need only ~5000 elements in the offset array which is far from being big. Use this answer (http://stackoverflow.com/questions/8762569/how-is-2d-bin-packing-achieved-programmatically/10339522) to calculate those offsets.

  2. Write the image header to file stream (see the 54-byte header for .BMP format for example)

  3. The "inefficient" part: Write (100k-by-100k)*BytesPerPixel zeroes to the file and then iterate the images writing them to this file one by one.

The InsertImageToStream() is done line-by-line, I think it is pretty straight-forward.

Optimization for the step 3: When the offsets[] array is sorted by Y and then by X you can optimally fill each scanline of the resulting image without excessive FileStream.seek() calls.

Viktor Latypov
  • 14,289
  • 3
  • 40
  • 55
  • pratical usage: mosaic with full resolution tiles you actually can zoom on – Mauro Sampietro Feb 11 '14 at 16:19
  • maybe for the rendering of this mosaic you shouldn't create this big bitmap ? just calculate current coordinates of the upper left corner of each tile and render individual images. this (individual tiles rendering) allows to render only the visible tiles, not the whole 100k-100k image. I'm sorry for rather offensive "yet to be known" comment, in a couple of years 100k by 100k might not be extremely large, but still it is better to avoid creation of the big bitmap entirely. – Viktor Latypov Feb 12 '14 at 08:04