iipmooviewer2-client rounding errors

Help
njfranck
2012-01-05
2012-10-06
  • njfranck

    njfranck - 2012-01-05

    Hi there,

    I tried the new iipmooviewer2 beta as found on http://merovingio.c2rmf.cnrs.f
    r/iipimage/iipmooviewer-2.0/.

    The method "calculateSizes" contains a rouding error, that only emerges when
    dealing with small tiles:

    max-size:
    w: 2561, h:2563, tile-width:256,tile-height:256

    in the method "calculateSizes" this is written:

    tx = Math.floor(tx/2);ty = Math.floor(ty/2);
    

    but it should be this:

    tx = Math.ceil(tx/2); ty = Math.ceil(ty/2);
    

    that way at 2561/2 does not become 1280 (and therefore thinking of 5 tiles in
    width),
    but 1281 (so actually 6 tiles), because a tile of width 1px needs to be there
    ;-)

     
  • Ruven

    Ruven - 2012-01-05

    Are you getting wrong calculations with your images? The calculation in
    calculateSizes() is to determine the sizes of each resolution, which it seems
    is always floor(tx/2). However, the calculation of the number of tiles in fact
    occurs in the loadGrid() function where there is indeed a ceil():

    var xtiles = Math.ceil( this.wid / this.tileSize.h );
    var ytiles = Math.ceil( this.hei / this.tileSize.h );
    

    Do you have an example where this does not work correctly?

     
  • njfranck

    njfranck - 2012-01-06

    consider this image: http://50.17.222.182/local/RUG01-001408817_2011_0001_AC.
    jp2

    width: 2561
    height: 2563

    this is wat calculateSizes does for one resolution:
    2561/2 = 1280.5;

    this resolution should have 6 tiles in width: 1280.5 / 256 = 5.001953125
    yes it's 5.001953125, but that means that it contains a very small tile in
    width,
    but that is crucial for the correct working of the client. Ceiling the value
    to 6 corrects this values

    but 1280 is stored due to floor

    zoomIn then calculates this.wid from this resolution-hash

    // Get the image size for this resolution
    this.wid = this.resolutions[this.view.res].w;
    this.hei = this.resolutions[this.view.res].h;
    

    loadGrid() then simple uses this.wid to determine the number of tiles, but the
    rounding
    error already occurred in a previous state.

    Maybe better to avoid rounding the numbers in the hash this.resolutions?

     
  • njfranck

    njfranck - 2012-01-06

    I mean: 1280/256 just gives you 5 tiles, instead of 6 actually in width

     
  • Ruven

    Ruven - 2012-01-06

    this resolution should have 6 tiles in width: 1280.5 / 256 = 5.001953125

    Not really, because you cannot have a real resolution with a fraction of a
    pixel. The resolutions in the TIFF or JEG2000 are physically generated at
    sizes that are rounded down.

     
  • njfranck

    njfranck - 2012-01-06

    Strange, but the example-jpeg2000 only works correctly when I make this
    "corrections". Just try it out ;-)

     
  • Ruven

    Ruven - 2012-01-06

    You're right. Your image contains the following resolutions:
    2561 x 2543
    1281 x 1272
    641 x 636
    321 x 318
    161 x 159
    81 x 80
    41 x 40
    21 x 20

    so it's in fact rounding up every time. I tried recompressing with Kakadu and
    it gives the same result. With TIFF, however, these resolutions are rounded
    down. Perhaps the solution would be for the server to send a list of available
    resolutions, rather than trying to calculate this?

     
  • njfranck

    njfranck - 2012-01-09

    I think so ;-). Either way, the server knows more about the file than the
    client ever will. And it makes the client more simple.

     


Anonymous

Cancel  Add attachments





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

Sign up for the SourceForge newsletter:





No, thanks