Efficiently split very large image in many tiny tiles #1666
Unanswered
TanukiSharp
asked this question in
Q&A
Replies: 2 comments 3 replies
-
For those who might be interested, I found a very straightforward and satisfying way to do it: private static Image<Rgba32> Extract(Image<Rgba32> sourceImage, Rectangle sourceArea)
{
Image<Rgba32> targetImage = new(sourceArea.Width, sourceArea.Height);
int height = sourceArea.Height;
for (int i = 0; i < height; i++)
{
Span<Rgba32> sourceRow = sourceImage.GetPixelRowSpan(sourceArea.Y + i);
Span<Rgba32> targetRow = targetImage.GetPixelRowSpan(i);
sourceRow.Slice(sourceArea.X, sourceArea.Width).CopyTo(targetRow);
}
return targetImage;
} I could parallelize the |
Beta Was this translation helpful? Give feedback.
1 reply
-
Is GetPixelRowSpan gone? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, and first, great work on this library.
Here is my problematic, I have a very large image loaded in memory, the file can be between 700 MB to 1 GB, and I need to split it in tiles of, let's say, 256 x 256 pixels. Tile size is customizable and doesn't have to be a power of 2.
So far, from what I understood, I have to clone the image and crop it.
Let's assume (very rough numbers but good enough for the example) the loaded image in memory takes 1 GB and one tile take 30 KB, then on a machine with only 1.1 GB of memory, cloning and cropping wouldn't work. I don't want to throw money at that to get more memory because it still feels like wasting, and it's probably going to be very slow.
Another approach could be to load, mutate / crop to tile, save, then load the original again and mutate / crop again, and so on, but this still feels inelegant.
I thought about creating a new image of 256 x 256 pixels for the tile and draw to it with the
DrawImage
processor, but it seems I can't decide which area of the source image to draw to the target tile image. I tried to useResizeMode.Crop
on resize, but so far I could only get a "resize effects" and never a "crop with no scaling".I searched StackOverflow but didn't find anything that looked like my problem.
Any suggestion is good to hear, thanks for your help.
Beta Was this translation helpful? Give feedback.
All reactions