Skip to content

Commit

Permalink
- Use PHOTOMETRIC-enum from tifffile for photometric interpretation. (#…
Browse files Browse the repository at this point in the history
…47)

- Use PHOTOMETRIC-enum from tifffile for photometric interpretation.
- Update imagecodecs to 2022.9.26.
  • Loading branch information
erikogabrielsson authored Nov 24, 2022
1 parent 2a0dd93 commit 3b19c17
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 179 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased] - ...


## [0.4.2] - 2022-11-24
### Fixed
- Use PHOTOMETRIC-enum from tifffile for photometric interpretation.
- Update imagecodecs to 2022.9.26.

## [0.4.1] - 2022-11-24
### Fixed
- Added missing tag in Philips tiff tiler.
Expand Down Expand Up @@ -59,7 +65,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Initial release of opentile.

[Unreleased]: https://github.com/imi-bigpicture/opentile/compare/v0.4.1..HEAD
[Unreleased]: https://github.com/imi-bigpicture/opentile/compare/v0.4.2..HEAD
[0.4.2]: https://github.com/imi-bigpicture/opentile/compare/v0.4.1..v0.4.2
[0.4.1]: https://github.com/imi-bigpicture/opentile/compare/v0.4.0..v0.4.1
[0.4.0]: https://github.com/imi-bigpicture/opentile/compare/v0.3.0..v0.4.0
[0.3.0]: https://github.com/imi-bigpicture/opentile/compare/v0.2.0..v0.3.0
Expand Down
2 changes: 1 addition & 1 deletion opentile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

from opentile.interface import OpenTile

__version__ = '0.4.1'
__version__ = '0.4.2'
8 changes: 4 additions & 4 deletions opentile/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from typing import List, Optional, Sequence, Tuple

import numpy as np
from tifffile.tifffile import (COMPRESSION, FileHandle, TiffFile, TiffPage,
TiffPageSeries, TiffTags)
from tifffile.tifffile import (COMPRESSION, PHOTOMETRIC, FileHandle, TiffFile,
TiffPage, TiffPageSeries, TiffTags)

from opentile.geometry import Point, Region, Size, SizeMm
from opentile.jpeg import Jpeg
Expand Down Expand Up @@ -136,9 +136,9 @@ def compression(self) -> COMPRESSION:
return COMPRESSION(self._page.compression)

@property
def photometric_interpretation(self) -> str:
def photometric_interpretation(self) -> PHOTOMETRIC:
"""Return photometric interpretation, e.g. 'YCBCR" or "RGB"."""
return str(self._page.photometric).split('.', maxsplit=1)[1]
return PHOTOMETRIC(self._page.photometric)

@property
def subsampling(self) -> Optional[Tuple[int, int]]:
Expand Down
16 changes: 7 additions & 9 deletions opentile/histech_tiff_tiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from pathlib import Path
from typing import Dict, Optional, Tuple, Union

from tifffile.tifffile import FileHandle, TiffFile, TiffPage, TiffPageSeries
from tifffile.tifffile import (PHOTOMETRIC, FileHandle, TiffFile, TiffPage,
TiffPageSeries)

from opentile.common import NativeTiledPage, Tiler
from opentile.geometry import Size, SizeMm
Expand Down Expand Up @@ -63,14 +64,11 @@ def mpp(self) -> SizeMm:
return self._mpp

@property
def photometric_interpretation(self) -> str:
photometric_interpretation = str(
self._page.photometric
).split('.', maxsplit=1)[1]
if photometric_interpretation == 'PALETTE':
return 'MINISBLACK'
else:
return photometric_interpretation
def photometric_interpretation(self) -> PHOTOMETRIC:
photometric_interpretation = PHOTOMETRIC(self._page.photometric)
if photometric_interpretation == PHOTOMETRIC.PALETTE:
return PHOTOMETRIC.MINISBLACK
return photometric_interpretation

def _get_mpp_from_page(self) -> SizeMm:
items_split = self._page.description.split('|')
Expand Down
2 changes: 1 addition & 1 deletion opentile/jpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def encode(self, data: np.ndarray) -> bytes:
bytes:
Encoded frame of data.
"""
return self._turbo_jpeg.encode(data)
return self._turbo_jpeg.encode(data, pixel_format=TJPF_RGB)

def crop_multiple(
self,
Expand Down
314 changes: 160 additions & 154 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "opentile"
version = "0.4.1"
version = "0.4.2"
description = "Read tiles from wsi-TIFF files"
authors = ["Erik O Gabrielsson <[email protected]>"]
license = "Apache-2.0"
Expand All @@ -20,7 +20,7 @@ tifffile = "^2022.5.4"
numpy = "^1.22.0"
PyTurboJPEG = "^1.6.1"
Pillow = "^9.1.1"
imagecodecs = "^2021.8.26"
imagecodecs = "^2022.9.26"

[tool.poetry.dev-dependencies]
pytest = "^5.2"
Expand Down
4 changes: 3 additions & 1 deletion tests/test_histech_tiff_tiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from hashlib import md5

import pytest
from tifffile.tifffile import PHOTOMETRIC

from opentile.histech_tiff_tiler import HistechTiffTiler

from .filepaths import histech_file_path
Expand Down Expand Up @@ -56,7 +58,7 @@ def test_get_tile(self):

def test_photometric_interpretation(self):
self.assertEqual(
'YCBCR',
PHOTOMETRIC.YCBCR,
self.tiler.get_level(0).photometric_interpretation
)

Expand Down
6 changes: 4 additions & 2 deletions tests/test_ndpi_tiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from datetime import datetime
import unittest
from datetime import datetime
from hashlib import md5
from typing import cast

import pytest
from tifffile.tifffile import PHOTOMETRIC

from opentile.geometry import Point, Size
from opentile.ndpi_tiler import (NdpiCache, NdpiFrameJob, NdpiStripedPage,
NdpiTile, NdpiTiler)
Expand Down Expand Up @@ -314,7 +316,7 @@ def test_adjust_tile_size(self):

def test_photometric_interpretation(self):
self.assertEqual(
'YCBCR',
PHOTOMETRIC.YCBCR,
self.tiler.get_level(0).photometric_interpretation
)

Expand Down
6 changes: 4 additions & 2 deletions tests/test_philips_tiff_tiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from datetime import datetime
import unittest
from datetime import datetime
from hashlib import md5

import pytest
from tifffile.tifffile import PHOTOMETRIC

from opentile.philips_tiff_tiler import PhilipsTiffTiler

from .filepaths import philips_file_path
Expand Down Expand Up @@ -56,7 +58,7 @@ def test_get_tile(self):

def test_photometric_interpretation(self):
self.assertEqual(
'YCBCR',
PHOTOMETRIC.YCBCR,
self.tiler.get_level(0).photometric_interpretation
)

Expand Down
6 changes: 4 additions & 2 deletions tests/test_svs_tiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from datetime import datetime
import unittest
from datetime import datetime
from hashlib import md5
from typing import cast

import pytest
from tifffile.tifffile import PHOTOMETRIC

from opentile.geometry import Point
from opentile.svs_tiler import SvsTiledPage, SvsTiler

Expand Down Expand Up @@ -91,7 +93,7 @@ def test_detect_corrupt_edges(self):

def test_photometric_interpretation(self):
self.assertEqual(
'RGB',
PHOTOMETRIC.RGB,
self.tiler.get_level(0).photometric_interpretation
)

Expand Down

0 comments on commit 3b19c17

Please sign in to comment.