Page 1 of 1

Tiff tiles on original position on jpg canvas

Posted: 2012-10-07T11:21:31-07:00
by martingriso
I have to create a tiling solution for incoming tiff files and the format of output tiles has to be jpg. Each tile has to be in separate file and located on a black canvas (same size as incoming tiff) on the same position as in the original tiff file. I found the following script that solves somewhat my problem but it is slow when incoming tiffs are large (~100MB) and therefore I'm looking for a better solution.

Code: Select all

 src=$1
 width=`identify -format %w $src`
 limit=$[$width / 256]
 echo "count = $limit * $limit = "$((limit * limit))" tiles"
 limit=$((limit-1))
 convert $src -alpha transparent -alpha extract canvas.png

 for x in `seq 0 $limit`; do
   for y in `seq 0 $limit`; do
     tile=tile-$x-$y.png
     echo -n $tile
     w=$((x * 256))
     h=$((y * 256))
     convert -debug cache -monitor $src -crop 256x256+$w+$h $tile
     convert -page +w+h canvas.png $tile -flatten $x-$y.jpg
   done
 done

Re: Tiff tiles on original position on jpg canvas

Posted: 2012-10-09T16:29:22-07:00
by anthony
Try using tile crop
http://www.imagemagick.org/Usage/crop/#crop_tile
or near-equal-area cropping if you want overlaps,
http://www.imagemagick.org/Usage/crop/#crop_equal

BUT instead of using +repage to junk the canvas and offsets, fill out the canvas using a side effect of -coalesce, and junk the transparency.

For example...

Code: Select all

convert rose: -crop 35x23 \
            -set dispose background -coalesce \
            -background black -alpha remove \
            tiles_%02d.tiff
OR try -crop 3x3@

Hmmm there seems to be a bug in the coalesce as I am getting an initial white background for the 'starting canvas'
when I should be getting a transparent canvas.

Re: Tiff tiles on original position on jpg canvas

Posted: 2012-10-09T16:52:43-07:00
by magick
Add -background none to your command line. Does that produce expected results?

Re: Tiff tiles on original position on jpg canvas

Posted: 2012-10-09T19:01:41-07:00
by anthony
magick wrote:Add -background none to your command line. Does that produce expected results?
convert rose: -crop 35x23 \
-background none -set dispose background -coalesce \
-background black -alpha remove \
tiles_%02d.tiff

YES it does. However -coalesce MUST use a background none internally, as that is what is required for correct handling of GIF animations. Just about any GIF animation processing will go wrong without it.