Converting Pyramidal TIFF to JPEG2000

Help
syamashi
2012-10-03
2015-10-02
  • syamashi

    syamashi - 2012-10-03

    Hello,

    Is it possible to convert Pyramidal TIFF files to JPEG2000 file format? If
    not, could plain TIFFs be restored from Pyramidal TIFF files created with
    vips?

    Files are created with:

    % vips im_vips2tiff source_image output_image.tif:deflate,tile:256x256,pyramid

    Thanks,

     
  • Ruven

    Ruven - 2012-10-04

    Yes, you can convert to both JPEG2000 or flat TIFF. For JPEG2000 you'll need
    to use Kakadu or OpenJPEG. For flat TIFF you can use vips:

    % vips im_vips2tiff source_image output_image.tif:none,strip,flat

     
  • syamashi

    syamashi - 2012-10-05

    Thank you ruven, that's what I needed.

     
  • syamashi

    syamashi - 2012-10-05

    Hi again,

    Do you happen to know if ImageMagick can convert Pyramidal TIFF to JPEG2000?
    It seems that the outputs are generated in seven separate files which I
    believe they are associated with resolution levels. I'd like to get a single
    jp2 file as it's done with converting flat TIFF to JPEG2000.

    For flat TIFFs,

    % convert source_image -define numrlvls=7 -define jp2:tilewidth=1024 -define
    jp2:tileheight=1024 -define jp2:rate=0.02348 -define jp2:prg=rpcl -define
    jp2:mode=int -define jp2:prcwidth=1024 -define jp2:prcheight=1024 -define
    jp2:cblkwidth=64 -define jp2:cblkheight=64 -define jp2:sop output_image

    worked ok.

     
  • Ruven

    Ruven - 2012-10-06

    Just use the highest resolution jp2 image and delete the rest, which are just shrunk versions of the largest resolution.

     
  • syamashi

    syamashi - 2012-10-08

    Got ya. Thanks Ruven!!

     
  • syamashi

    syamashi - 2012-10-26

    Hi Ruven,

    I'm getting a different size of images when converted to JPEG2000 from what I had in TIF. It seems that the IIP server returns about the doubled in size with same request parameters.

    A. JPEG2000 returns 229x172 in size

    /fcgi-bin/iipsrv.fcgi?FIF=abc.jp2&HEI=80&CVT=JPEG&QLT=50

    B. TIF returns 106x79 in size

    /fcgi-bin/iipsrv.fcgi?FIF=abc.tif&HEI=80&CVT=JPEG&QLT=50

    How do I keep JPEG2000 remain the same size as TIF files? Would it be the parameters of the query or do I need to tweak the conversions made in ImageMagick?

    Thanks,

     
  • Ruven

    Ruven - 2012-10-26

    If you're images are very big, you should increase the number of resolution levels created with numrlvl for imagemagick. Or use Kakadu as described here:
    http://iipimage.sourceforge.net/documentation/images/

    By the way, the QLT= parameter should be before the CVT=JPEG

     
  • syamashi

    syamashi - 2012-10-29

    I did experiment with different resolution levels and none of them seem to affect the size. In fact, I tried 2, 8, 9, and all appeared to be the same size. Originally, both TIF and JPEG2000 were set at numrlvl=7 and they came out differently. Here is the command I ran:

    convert abc.tif -define numrlvls=9 -define jp2:tilewidth=256 -define jp2:tileheight=256 -define jp2:rate=0.02348 -define jp2:prg=rpcl -define jp2:mode=int -define jp2:prcwidth=256 -define jp2:prcheight=256 -define jp2:cblkwidth=64 -define jp2:cblkheight=64 -define jp2:sop abc.jp2

    Could it be other parameters which I need to tweak on either ImageMagick conversion or URL params? By the way, I might have skipped reading the document. Why does the order of QLT and CVG matter?

    thanks,

     
  • Ruven

    Ruven - 2012-10-29

    OK, I see what you're doing wrong now. You didn't correctly prefix numrlvls, meaning it only generates the default number of levels. It should be

    -define jp2:numrlvls=9
    

    And the CVT=JPEG parameter must always be the last parameter simply because anything after will not be taken into account

     
  • syamashi

    syamashi - 2012-10-30

    I added the prefix this time only to result in same sizes. Can you think of any other tweaks I could try? Do you know how to print out and confirm the resolution levels of converted JPEG2000 files?

     
    Last edit: syamashi 2012-10-30
  • Ruven

    Ruven - 2012-10-31

    I tried this myself and it does work. Set the value sufficiently high to create enough resolutions.

    You can use https://github.com/openplanets/jpylyzer to analyze your JPEG2000 image.

     
  • syamashi

    syamashi - 2012-11-01

    Yes, it does work on the viewer. I have two individual IIPMooviewers for TIFF and JPEG2000 and both sizes seem to synchronous in each level from zoom-in/zoom-out. However, grabbing files individually from iipsrv.fcgi is not. That's why I'm not yet convinced with increasing the numrlvls value.

    In the meantime, I have TIFF images in 14000x11000 dimension and over 1GB in size. It takes forever to convert beyond "numrlvls=10"... That's another reason why I'd like to find other way around for resizing the images. Would it be possible to resize an image from IIP parameters?

    By the way, does "levels" generated from jpylyzer matche the resolution levels? I wasn't sure on the usage of how to extract this value.

    thanks,

     
  • Ruven

    Ruven - 2012-11-02

    14000x11000 is not so big, so you won't need more than around 7 or 8 levels for this. If this is now working well in the viewers, that's good.

    But if you want exact resizing of JPEG2000 using CVT, make sure you are using the latest code from github. If you are using version 0.9.9 it will only resize to the nearest existing resolution level. So, you ask for HEI=80, it will give you the nearest existing resolution level bigger than 80px.

    In the latest code, it will do bilinear resizing for both TIFF and JPEG2000 to the exact size specified.

     
  • Ruven

    Ruven - 2012-11-03

    I believe your latest code is 1.0, correct?

    Well, it's not quite 1.0 yet, but will be when released.

    Where can I find a JPEG2000 supported deb file for installation?

    The only JPEG2000 builds at the moment are for version 0.9.9. We may put up test builds at some point before the full release of 1.0, but I can't guarantee anything.

     
  • syamashi

    syamashi - 2012-11-05

    Is there a way to force IIP server to return the lowest resolution level of an image with CVT? I did confirm that neither 7 or 8 levels return the image in 229x172 which supposed to be the 2nd resolution level. One thing I noticed is that I see "Memcached hit" in the logs.


    CVT maximum viewport size set to 5000
    Full Request is FIF=.....jp2&HEI=80&QLT=50&CVT=JPEG
    Memcached hit
    Total Request Time: 175 microseconds
    image closed and deleted
    Server count is 3


    I restarted Apache but I still get Memcache hits. Could the server be caching images? How do I clear the cache?

    thanks,

     
    Last edit: syamashi 2012-11-05
  • syamashi

    syamashi - 2012-11-05

    Well, I pointed to a different server so I managed to get around Memcached hits but I guess caching is irrelevant. Can I force the bilinear resizing to return the lowest resolution level as TIFF do with 106x79? I believe JPEG2000 should have suffice levels.

    CVT maximum viewport size set to 5000
    Full Request is FIF=....jp2&HEI=80&QLT=50&CVT=JPEG
    FIF handler reached
    FIF :: Image cache initialisation
    FIF :: JPEG2000 image requested
    FIF :: Created image
    FIF :: Image dimensions are 14712 x 11012
    FIF :: Image timestamp: Mon, 05 Nov 2012 18:16:43 GMT
    FIF :: Total command time 490941 microseconds
    [2/4]: Command / Argument is HEI : 80
    HEI handler reached
    HEI :: requested height is 80
    [3/4]: Command / Argument is QLT : 50
    [4/4]: Command / Argument is CVT : JPEG
    CVT handler reached
    CVT :: JPEG output handler reached
    CVT :: image set to 230x173 using resolution 0
    CVT :: No view port set
    CVT :: Requested scaled region size is 106x80. Nearest pyramid region size is 230x173
    CVT :: About to JPEG compress image
    CVT :: Compressed data strip length is 1873
    CVT :: Total command time 179009 microseconds
    Memcached :: stored 2091 bytes in 25 microseconds
    Total Request Time: 671400 microseconds
    image closed and deleted


    CVT maximum viewport size set to 5000
    Full Request is FIF=....tif&HEI=80&QLT=50&CVT=JPEG
    FIF handler reached
    FIF :: Image cache miss
    FIF :: TIFF image requested
    FIF :: Created image
    FIF :: Image dimensions are 14712 x 11012
    FIF :: Image timestamp: Wed, 05 Sep 2012 19:10:11 GMT
    FIF :: Total command time 371407 microseconds
    [2/4]: Command / Argument is HEI : 80
    HEI handler reached
    HEI :: requested height is 80
    [3/4]: Command / Argument is QLT : 50
    [4/4]: Command / Argument is CVT : JPEG
    CVT handler reached
    CVT :: JPEG output handler reached
    CVT :: image set to 229x172 using resolution 0
    CVT :: No view port set
    CVT :: Requested scaled region size is 106x79. Nearest pyramid region size is 229x172
    TileManager :: Cache Miss for resolution: 0, tile: 0
    TileManager :: Cache Size: 0 tiles, 0 MB
    TileManager :: Tile cache insertion time: 737 microseconds
    TileManager :: Total Tile Access Time: 1751 microseconds
    CVT :: Tile access time 1919 microseconds for tile 0 at resolution 0
    CVT :: Tile data is 3 channels, 8 bits per channel
    CVT :: resampled strip height 79
    CVT :: Performing resampling with scale 0.462882
    CVT :: Compressed data strip length is 843
    CVT :: Total command time 2551 microseconds
    Memcached :: stored 1061 bytes in 370 microseconds
    Total Request Time: 374546 microseconds
    image closed and deleted

     
  • Ruven

    Ruven - 2012-11-06

    Bilinear resizing is also only available in the development code on github.

     
  • syamashi

    syamashi - 2012-11-07

    Hi Ruven,

    Ok. Well, I'll look forward to the new JPEG2000 build then. There are clearly a couple of things I don't know how to confirm or try at this minute:

    1. How to disable Memcache on the server? ---> Setting the MEMCACHED_TIMEOUT=1 didn't work because I still see "Memcached hit" in the logs.

    2. How to confirm the size or dimension of the lowest resolution level of an image? ----> Couldn't figure out how to read the output of jpylyzer for the size of the lowest resolution level.

    3. How to minify the size of the lowest resolution level during JPEG2000 conversion with level? ---> If the lowest pyramidal region size is 229x172 with numrlvls=7 or numrlvls=8, how to make the size smaller with those levels?

    If you know the answers to these questions, it would help greatly because I can avoid creating different JPEG2000 files or use TIFFs just for the purpose of generating thumbnails.

    thanks,

     
    Last edit: syamashi 2012-11-07
  • syamashi

    syamashi - 2012-11-09

    I've confirmed that both Pyramidal TIFF and JPEG2000 respectively have the same dimensions on every level. The lowest being "229 x 172". So I'd have to assume that the file conversion is working.

    What I see here is that the scaling with "HEI,WID,CVT,QLT" parameters with a TIFF and a JPEG2000 seem to give different results in size. TIFFs seem to scale accordingly with given HEI or WID values as opposed to JPEG2000 returning a constant size once it reaches certain values. In my case, TIFFs scale to "106x79" when HEI=80 is given but JPEG2000s remain with the dimension of lowest resolution level no matter how small the HEI/WID are given. It seems like TIFFs are smarter or more accurate in scaling.

    I don't know if this is due to the bilinear resizing or the spec of JPEG2000 but I hope I can get consistent sizes from both file formats. Hopefully, the next build version can incorporate that.

     
    Last edit: syamashi 2012-11-09
  • Ruven

    Ruven - 2012-11-09

    I don't know if this is due to the bilinear resizing or the spec of JPEG2000 but I hope I can get consistent sizes from both file formats. Hopefully, the next build version can incorporate that.

    Yes. This is already in the latest development code and will definitely be in version 1.0.

     
  • syamashi

    syamashi - 2012-11-09

    When are you planning to release 1.0? It'd be great to know just a rough ETA.

     
  • Ruven

    Ruven - 2012-11-09

    I can't give a precise date, but it'll take several months at least.

     
  • gvjump

    gvjump - 2013-07-04

    you can absolutely convert tiff to jpeg vb.net as long as you have the value of high resolution. there is difference between pyramidal and flat.

     


Anonymous

Cancel  Add attachments





Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks