Page 1 of 1

mosaic jpegs w/ size a multiple of tile size w/o recompres

Posted: 2011-05-19T10:57:40-07:00
by NicolasRobidoux
Suppose that you have a collection of jpeg thumbails with fixed width and height, both of them an exact multiple of the tile size (8 if using -sampling-factor 1x1 and 16 if using -sampling-factor 2x2).

For example, a collection of 40x40 JPEG thumbnails done using -sampling-factor 1x1 (and somewhat low quality).

Is there an easy way to assemble them into a mosaic jpeg strip (vertical or horizontal) without decompression/recompression artifacts?

My understanding is that generically the individual thumbnails will be decompressed, assembled into a mosaic, and then recompressed, and this will introduce artifacts, even if the JPEG parameters are the same across the board.

What I want to do is exploit the fact that JPEG compression is done one tile at a time, so the result, in principle, should be the same if I assemble the mosaic "directly." I'm guessing it's not (but have not checked yet).

(I actually am assuming that the usual ways of assembling the mosaic would be lossy. Is IM smart enough to assemble losslessly without special handling in my special case? Of course, if you have dimensions VS JPEG tile mismatch, doing this losslessly is basically impossible within the JPEG framework.)

Re: mosaic jpegs w/ size a multiple of tile size w/o recompr

Posted: 2011-05-19T12:45:33-07:00
by fmw42
As far as I know, IM will decompress and recompress. So you probably need to look for some other custom non-IM solution.

Re: mosaic jpegs w/ size a multiple of tile size w/o recompr

Posted: 2011-05-19T18:38:51-07:00
by anthony
I would look at the source code of jpegtrans. Others have already figured out extracting and rearraging the JPEG tile cells. appropriately. I think they have also crop and insert type functions too.
If so you may be able just create a new large JPEG and insert the data into it ;-)
That is essentially how IM does append internally!

However be aware that while JPEG saves image data as YCrCb colorspace you may have to be sure all the other attributes are the same in between the two JPEG images.

Please let us know how you go, and if you publish a 'JPEG append' type program.

Re: mosaic jpegs w/ size a multiple of tile size w/o recompr

Posted: 2011-05-20T07:50:19-07:00
by NicolasRobidoux
anthony wrote:I would look at the source code of jpegtrans. Others have already figured out extracting and rearraging the JPEG tile cells. appropriately. I think they have also crop and insert type functions too.
If so you may be able just create a new large JPEG and insert the data into it ;-)
...
Thank you Anthony (and Fred).

Without knowing the details, I figured that it would be likely that one have to do it like you describe.

Because the person I'm helping has the "pre-thumbnail/pre-resize" jpeg original images, it may just be simpler to preassemble "internally" in hdri mode and produce the jpeg mosaic strip at the very end (instead of storing the individual thumbnails to be mosaiced).

But if it's not practical for him to do what I just described, I'll let you know what we come up with.

Things are simpler for us than the more general situation you describe: We control how all the thumbnails are produced, they are all done exactly the same way (save for image content, of course), and we -strip after converting to sRGB.

FYI, we are constructing JPEG sprites, which I am not sure anybody has done before?

Re: mosaic jpegs w/ size a multiple of tile size w/o recompr

Posted: 2011-05-20T09:39:01-07:00
by fmw42
perhaps save all the thumbnails as (lossless) png or tiff, then montage them or append them and save the result as jpg

Re: mosaic jpegs w/ size a multiple of tile size w/o recompr

Posted: 2011-05-20T11:32:12-07:00
by NicolasRobidoux
fmw42 wrote:perhaps save all the thumbnails as (lossless) png or tiff, then montage them or append them and save the result as jpg
I thought of this too.

It appears that we all agree on what to try.

Thank you Fred.