hadim / read-roi

Read ROI files .zip or .roi generated with ImageJ.
BSD 3-Clause "New" or "Revised" License
51 stars 22 forks source link

Big values (above 32768) for Coordinates #13

Closed OrlandoGrigo closed 4 years ago

OrlandoGrigo commented 4 years ago

Hello,

I just wanted to say that in large images, when one of the coordinates is larger than 32768 the integer passed to python is incorrect.

I just commented the following lines in the _read_roi.py file and it works for me:

if n >= 32768: # 215 n -= 65536 # 216

Please correct me if what i did can cause any problems

scottclowe commented 4 years ago

This will break any negative co-ordinates, which occur when people draw outside the left and top boundaries of the image. It is particularly common for this to happen when using the oval or ellipse tool to draw a shape on the boundary of the image.

Since it only has 16 bits with which to encode the output, I expect ImageJ is saving the data with a bijective mapping. Both co-ordinates at 65436 and at -100 will be saved to the same binary data, and it is impossible to distinguish between them (the same data could be int16 or uint16 encoding).

Since it is highly improbable that someone saves data at a co-ordinate of −32768, but more likely they saved it -100 than 65436, I think the best solution is to pick some threshold at which the best-guess changes from uint16 to int16 data.

scottclowe commented 4 years ago

Thanks for reporting this, @OrlandoGrigo. I implemented a solution to the bijective mapping of negative values and values >32768 as I described above. If you upgrade to v1.6.0, you should find your ROIs on big images work now, up to a size of 65035 pixels. Negative co-ordinate values are still supported, provided they are >=-500.