Skip to content

Commit

Permalink
Fix-create-new-levels (#162)
Browse files Browse the repository at this point in the history
* Fix image size calculation

* Sort levels to get closest

* Update changelog

* Update version
  • Loading branch information
erikogabrielsson authored Mar 25, 2024
1 parent 46fae89 commit 6a35682
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.20.4] - 2024-03-25

### Fixed

- Error when calculating downscaled image size causing `save()` with `add_missing_levels` to fail.
- Missing sort when creating new pyramid levels, causing new levels to be created from a to high resolution level.

## [0.20.3] - 2024-03-20

### Fixed
Expand Down Expand Up @@ -359,7 +366,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Initial release of wsidicom

[Unreleased]: https://github.com/imi-bigpicture/wsidicom/compare/0.20.3..HEAD
[Unreleased]: https://github.com/imi-bigpicture/wsidicom/compare/0.20.4..HEAD
[0.20.4]: https://github.com/imi-bigpicture/wsidicom/compare/v0.20.3..v0.20.4
[0.20.3]: https://github.com/imi-bigpicture/wsidicom/compare/v0.20.2..v0.20.3
[0.20.2]: https://github.com/imi-bigpicture/wsidicom/compare/v0.20.1..v0.20.2
[0.20.1]: https://github.com/imi-bigpicture/wsidicom/compare/v0.20.0..v0.20.1
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "wsidicom"
version = "0.20.3"
version = "0.20.4"
description = "Tools for handling DICOM based whole scan images"
authors = ["Erik O Gabrielsson <[email protected]>"]
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion wsidicom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from wsidicom.web import WsiDicomWebClient
from wsidicom.wsidicom import WsiDicom

__version__ = "0.20.3"
__version__ = "0.20.4"

__all__ = [
"settings",
Expand Down
4 changes: 3 additions & 1 deletion wsidicom/file/wsidicom_file_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ def _save_pyramid(self, pyramid: Pyramid):
closest_new_level = next(
(
level
for level in new_levels
for level in sorted(
new_levels, key=lambda x: x.level, reverse=True
)
if level.level < pyramid_level
and level.level > closest_level.level
),
Expand Down
11 changes: 8 additions & 3 deletions wsidicom/instance/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import io
import logging
import math
from dataclasses import dataclass
from enum import Enum, IntEnum, auto
from functools import cached_property
Expand Down Expand Up @@ -710,16 +711,20 @@ def as_tiled_full(
if "PerFrameFunctionalGroupsSequence" in dataset:
del dataset["PerFrameFunctionalGroupsSequence"]

dataset.TotalPixelMatrixColumns = max(
math.ceil(dataset.TotalPixelMatrixColumns / scale), 1
)
dataset.TotalPixelMatrixRows = max(
math.ceil(dataset.TotalPixelMatrixRows / scale), 1
)
dataset.TotalPixelMatrixFocalPlanes = len(focal_planes)
dataset.NumberOfOpticalPaths = len(optical_paths)
dataset.NumberOfFrames = (
max(tiled_size.ceil_div(scale).area, 1)
* len(focal_planes)
* len(optical_paths)
)
scaled_size = dataset.image_size.ceil_div(scale)
dataset.TotalPixelMatrixColumns = max(scaled_size.width, 1)
dataset.TotalPixelMatrixRows = max(scaled_size.height, 1)

return dataset

@classmethod
Expand Down

0 comments on commit 6a35682

Please sign in to comment.