Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update libCZI and fix shape error #124

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions _aicspylibczi/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class Image : public SubblockSortable
, m_shape(std::move(shape_))
, m_pixelType(pixel_type_)
, m_xywh(box_)
{}
{
}

size_t calculateIdx(const std::vector<size_t>& indexes_);

Expand Down Expand Up @@ -144,8 +145,9 @@ class ImageVector : public std::vector<std::shared_ptr<Image>>
size_t hByWsize = heightByWidth.size();
charSizes.emplace_back('Y', heightByWidth[0]); // H: 0
charSizes.emplace_back('X', heightByWidth[1]); // W: 1
if (hByWsize > 2)
if (hByWsize > 2) {
charSizes.emplace_back('A', heightByWidth[2]); // A: 3
}
// sort them into decending DimensionIndex Order
std::sort(charSizes.begin(), charSizes.end(), [&](std::pair<char, size_t> a_, std::pair<char, size_t> b_) {
return libCZI::Utils::CharToDimension(a_.first) > libCZI::Utils::CharToDimension(b_.first);
Expand Down
20 changes: 8 additions & 12 deletions _aicspylibczi/Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,21 @@ Reader::sceneShape(int scene_index_)
definedDims[dimensionIndexToDimIndex(di_)].emplace(val_);
return true;
});
if (isMosaic())
if (isMosaic()) {
definedDims[DimIndex::M].emplace(x.first.mIndex());
}
}
for (auto x : definedDims)
for (auto x : definedDims) {
tbl.emplace(x.first, std::make_pair(*x.second.begin(), *x.second.rbegin() + 1));
}

auto xySize = getSceneYXSize(scene_index_);
tbl.emplace(DimIndex::Y, std::make_pair(0, xySize.h));
tbl.emplace(DimIndex::X, std::make_pair(0, xySize.w));
}
if (ImageFactory::numberOfSamples(m_pixelType) > 1)
if (ImageFactory::numberOfSamples(m_pixelType) > 1) {
tbl.emplace(charToDimIndex('A'), std::make_pair(0, ImageFactory::numberOfSamples(m_pixelType)));
}

return tbl;
}
Expand All @@ -206,18 +209,11 @@ Reader::getAllSceneYXSize(int scene_index_, bool get_all_matches_)
{
std::vector<libCZI::IntRect> result;
bool hasScene = m_statistics.dimBounds.IsValid(libCZI::DimensionIndex::S);
if (!isMosaic() && hasScene) {
int sStart(0), sSize(0);
m_statistics.dimBounds.TryGetInterval(libCZI::DimensionIndex::S, &sStart, &sSize);
if (scene_index_ >= sStart && (sStart + sSize - 1) >= scene_index_ && !m_statistics.sceneBoundingBoxes.empty()) {
result.emplace_back(m_statistics.sceneBoundingBoxes[scene_index_].boundingBoxLayer0);
return result;
}
}
Copy link
Collaborator Author

@toloudis toloudis Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method which uses boundingBoxLayer0 can return a different result than the following code which uses the subblock logicalRects. Preferring the logicalRect gives consistency between expected shape and read shape. Therefore I am removing this short-cut attempt to read the scene YX shape

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Dan, I've reviewed the changes you've made and agree with them.


libCZI::CDimCoordinate scene_coord; // default constructor
if (hasScene && scene_index_ >= 0)
if (hasScene && scene_index_ >= 0) {
scene_coord = libCZI::CDimCoordinate({ { libCZI::DimensionIndex::S, scene_index_ } });
}
SubblockSortable subblocksToFind(&scene_coord, -1, false);
SubblockIndexVec matches = getMatches(subblocksToFind);

Expand Down
16 changes: 7 additions & 9 deletions _aicspylibczi/Reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class Reader
ImagesContainerBase::ImagesContainerBasePtr readMosaic(libCZI::CDimCoordinate plane_coord_,
float scale_factor_ = 1.0,
libCZI::IntRect im_box_ = { 0, 0, -1, -1 },
libCZI::RgbFloatColor backGroundColor_ = { 0.0, 0.0, 0.0 });
libCZI::RgbFloatColor backGroundColor_ = { 0.0, 0.0, 0.0 });

/*!
* Convert the libCZI::DimensionIndex to a character
Expand All @@ -261,7 +261,6 @@ class Reader

virtual ~Reader() { m_czireader->Close(); }


/*!
* @brief get the shape of the loaded images
* @param images_ the ImageVector of images to get the shape of
Expand Down Expand Up @@ -347,15 +346,15 @@ class Reader
void checkSceneShapes();

/*!
* @brief get the pyramid 0 (acquired data) shape
* @param scene_index_ specifies scene but defaults to the first scene,
* Scenes can have different sizes
* @return std::vector<libCZI::IntRect> containing (x0, y0, w, h)
*/
* @brief get the pyramid 0 (acquired data) shape
* @param scene_index_ specifies scene but defaults to the first scene,
* Scenes can have different sizes
* @return std::vector<libCZI::IntRect> containing (x0, y0, w, h)
*/
libCZI::IntRect getSceneYXSize(int scene_index_ = -1)
{
std::vector<libCZI::IntRect> matches = getAllSceneYXSize(scene_index_);
return matches.empty() ? libCZI::IntRect{ 0,0,0,0 } : matches.front();
return matches.empty() ? libCZI::IntRect{ 0, 0, 0, 0 } : matches.front();
}

/*!
Expand All @@ -368,7 +367,6 @@ class Reader
std::vector<libCZI::IntRect> getAllSceneYXSize(int scene_index_ = -1, bool get_all_matches_ = false);

libCZI::PixelType getFirstPixelType();

};

}
Expand Down
12 changes: 10 additions & 2 deletions aicspylibczi/CziFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,13 @@ def read_image(self, **kwargs):
image, shape = self.reader.read_selected(plane_constraints, m_index, cores)
return image, shape

def read_mosaic(self, region: Tuple = None, scale_factor: float = 1.0, background_color: Tuple = None, **kwargs):
def read_mosaic(
self,
region: Tuple = None,
scale_factor: float = 1.0,
background_color: Tuple = None,
**kwargs,
):
"""
Reads a mosaic file and returns an image corresponding to the specified dimensions. If the file is more than
a 2D sheet of pixels, meaning only one channel, z-slice, time-index, etc then the kwargs must specify the
Expand Down Expand Up @@ -619,7 +625,9 @@ def read_mosaic(self, region: Tuple = None, scale_factor: float = 1.0, backgroun
tmp.b = background_color[2]
background_color = tmp

img = self.reader.read_mosaic(plane_constraints, scale_factor, region, background_color)
img = self.reader.read_mosaic(
plane_constraints, scale_factor, region, background_color
)

return img

Expand Down
2 changes: 1 addition & 1 deletion libCZI
Submodule libCZI updated 99 files
+144 −19 .github/workflows/cmake.yml
+3 −2 .github/workflows/mega-linter.yml
+17 −1 CMakeLists.txt
+17 −2 Src/CMakeLists.txt
+0 −2 Src/CZICmd/BitmapGen.cpp
+0 −1 Src/CZICmd/BitmapGenFreeType.cpp
+4 −5 Src/CZICmd/BitmapGenGdiplus.cpp
+4 −5 Src/CZICmd/BitmapGenNull.cpp
+11 −5 Src/CZICmd/BitmapGenNull.h
+39 −25 Src/CZICmd/CMakeLists.txt
+7 −13 Src/CZICmd/CZIcmd.cpp
+ Src/CZICmd/CZIcmd.ico
+3 −0 Src/CZICmd/CZIcmd.ico.license
+10 −0 Src/CZICmd/CZIcmd.manifest
+3 −0 Src/CZICmd/CZIcmd.manifest.license
+73 −0 Src/CZICmd/CZIcmd.rc
+4 −1 Src/CZICmd/CZIcmd_Config.h.in
+24 −21 Src/CZICmd/SaveBitmap.cpp
+6 −7 Src/CZICmd/cmdlineoptions.cpp
+0 −2 Src/CZICmd/consoleio.cpp
+3 −0 Src/CZICmd/consoleio.h
+0 −1 Src/CZICmd/execute.cpp
+0 −1 Src/CZICmd/executeCreateCzi.cpp
+0 −1 Src/CZICmd/executePlaneScan.cpp
+1 −1 Src/CZICmd/inc_rapidjson.h
+0 −13 Src/CZICmd/platform_defines.h
+18 −0 Src/CZICmd/resource_data.h.in
+0 −11 Src/CZICmd/stdafx.cpp
+0 −28 Src/CZICmd/stdafx.h
+0 −14 Src/CZICmd/targetver.h
+3 −3 Src/CZICmd/utils.cpp
+2 −1 Src/CZICmd/utils.h
+2 −1 Src/Doxyfile
+2 −2 Src/JxrDecode/jxrlib/image/encode/strenc.c
+2 −2 Src/JxrDecode/jxrlib/jxrgluelib/JXRGlue.c
+2 −2 Src/JxrDecode/jxrlib/jxrgluelib/JXRGlueJxr.c
+1 −1 Src/libCZI/BitmapOperations.cpp
+39 −13 Src/libCZI/CMakeLists.txt
+4 −8 Src/libCZI/CziAttachment.cpp
+1 −2 Src/libCZI/CziAttachment.h
+3 −3 Src/libCZI/CziDisplaySettings.cpp
+2 −2 Src/libCZI/CziDisplaySettings.h
+9 −3 Src/libCZI/CziMetadata.cpp
+104 −46 Src/libCZI/CziMetadataBuilder.cpp
+3 −3 Src/libCZI/CziMetadataBuilder.h
+58 −56 Src/libCZI/CziMetadataDocumentInfo.cpp
+1 −4 Src/libCZI/CziMetadataSegment.cpp
+1 −2 Src/libCZI/CziMetadataSegment.h
+56 −37 Src/libCZI/CziParse.cpp
+17 −4 Src/libCZI/CziParse.h
+4 −8 Src/libCZI/CziSubBlock.cpp
+1 −2 Src/libCZI/CziSubBlock.h
+3 −5 Src/libCZI/CziUtils.cpp
+32 −25 Src/libCZI/CziWriter.cpp
+4 −3 Src/libCZI/CziWriter.h
+2 −2 Src/libCZI/DimCoordinate.cpp
+1 −0 Src/libCZI/Doc/building_libCZI.markdown
+64 −0 Src/libCZI/Doc/stream_objects.markdown
+16 −1 Src/libCZI/Doc/version-history.markdown
+5 −5 Src/libCZI/IndexSet.cpp
+1 −1 Src/libCZI/IndexSet.h
+41 −39 Src/libCZI/MultiChannelCompositor.cpp
+1 −1 Src/libCZI/SingleChannelAccessorBase.cpp
+2 −2 Src/libCZI/StreamImpl.cpp
+5 −5 Src/libCZI/StreamImpl.h
+306 −0 Src/libCZI/StreamsLib/azureblobinputstream.cpp
+139 −0 Src/libCZI/StreamsLib/azureblobinputstream.h
+13 −0 Src/libCZI/StreamsLib/curlhttpinputstream.cpp
+6 −6 Src/libCZI/StreamsLib/simplefileinputstream.cpp
+2 −2 Src/libCZI/StreamsLib/simplefileinputstream.h
+18 −4 Src/libCZI/StreamsLib/streamsFactory.cpp
+1 −1 Src/libCZI/StreamsLib/windowsfileinputstream.cpp
+1 −1 Src/libCZI/StreamsLib/windowsfileinputstream.h
+41 −44 Src/libCZI/XmlNodeWrapper.h
+9 −8 Src/libCZI/decoder_wic.cpp
+3 −1 Src/libCZI/decoder_wic.h
+5 −4 Src/libCZI/libCZI.h
+8 −0 Src/libCZI/libCZI_Config.h.in
+9 −8 Src/libCZI/libCZI_Helpers.h
+2 −2 Src/libCZI/libCZI_Lib.cpp
+40 −7 Src/libCZI/libCZI_Metadata.h
+4 −3 Src/libCZI/libCZI_Site.cpp
+7 −2 Src/libCZI/libCZI_StreamsLib.h
+4 −4 Src/libCZI/libCZI_Utilities.cpp
+5 −1 Src/libCZI/libCZI_Write.h
+3 −1 Src/libCZI/stdAllocator.h
+135 −23 Src/libCZI/utilities.cpp
+22 −8 Src/libCZI/utilities.h
+3 −1 Src/libCZI_UnitTests/CMakeLists.txt
+44 −44 Src/libCZI_UnitTests/MockMetadataSegment.cpp
+219 −3 Src/libCZI_UnitTests/test_CZIParse.cpp
+214 −0 Src/libCZI_UnitTests/test_DisplaySettings.cpp
+91 −0 Src/libCZI_UnitTests/test_Utilities.cpp
+185 −0 Src/libCZI_UnitTests/test_azureblobstream.cpp
+32 −1 Src/libCZI_UnitTests/test_curlhttpstream.cpp
+36 −2 Src/libCZI_UnitTests/test_metadatabuilder.cpp
+56 −5 Src/libCZI_UnitTests/test_metadatareading.cpp
+55 −1 Src/libCZI_UnitTests/test_writer.cpp
+1 −0 cmake/ExternalEIGEN3.cmake
2 changes: 1 addition & 1 deletion pybind11
Submodule pybind11 updated 205 files
Loading