Question

We have an application that show a large image file (satellite image) from local network resource. To speed up the image rendering, we divide the image to smaller patches (e.g. 6x6 cm) and the app tiles them appropriately. But each time the satellite image updated, the dividing pre-process should be done, which is a time consuming work.

I wonder how can we load the patches from the original file?

PS 1: I find the LeadTools library, but we need an open source solution.

PS 2: The app is in .NET C#

Edit 1: The format is not a point for us, but currently it's JPG. changing the format to a another could be consider, but BMP format is hardly acceptable, because of it large volume.

Was it helpful?

Solution

I wote a beautifull attempt of answer to your question, but my browser ate it... :(

Basically what I tried to say was:

1.- Since Jpeg (and most compression formats) uses a secuential compression, you'll always need to decode all the bits that are before the ones that you need.
2.- The solution I propose need to be done with each format you need to support.
3.- There are a lot of open source jpeg decoders that you could modify. Jpeg decoders need to decode blocks of bits (of variable size) that convert into pixel blocks of size 8x8. What you could do is modify the code to save in memory only the blocks you need and discard all the others as soon as they aren't needed any more (basically as soon as they are decoded). With those memory-saved blocks, create the image you need.
4.- Since Jpeg works with blocks of 8x8, your work could be easier if you work with patches of sizes multiples of 8 pixels.
5.- The modification done to the jpeg decoder could be used to substitute the preprocessing of the images you are doing if you save the patch and discard the blocks as soon as you complete them. It would be really fast and less memory consuming.

I know it needs a lot of work and there are a lot of details to be taken in consideration (specially if you work with color images), but if you need performance I belive you will always end fighting or playing (as you want to see it) with the bytes.

Hope it helps.

OTHER TIPS

I'm not 100% sure what you're after but if you're looking for a way to go from string imagePath, Rectangle desiredPortion to a System.Drawing.Image object then perhaps something like this:

public System.Drawing.Image LoadImagePiece(string imagePath, Rectangle desiredPortion)
{
   using (Image img = Image.FromFile(path))
   {
       Bitmap result = new Bitmap(desiredPortion.Width, desiredPortion.Height, PixelFormat.Format24bppRgb);
       using (Graphics g = Graphics.FromImage((Image)result))
       {
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            g.DrawImage(img, 0, 0, desiredPortion, GraphicsUnit.Pixel);
       }
       return result;
   }
}

Note that for performance reasons you may want to consider building multiple output images at once rather than calling this multiple times - perhaps passing it an array of rectangles and getting back an array of images or similar.

If that's not what you're after can you clarify what you're actually looking for?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top