Skip to content

Commit

Permalink
Merge pull request #103 from sameeul/binary_segmentation
Browse files Browse the repository at this point in the history
read binary segmentation image
  • Loading branch information
hsidky authored May 1, 2023
2 parents 967cef3 + 1ec7f47 commit cba754a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ci-utils/install_prereq_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ unzip v2.5.0.zip
cd openjpeg-2.5.0/
mkdir build_man
cd build_man/
cmake -DCMAKE_INSTALL_PREFIX=../../$Z5_INSTALL_DIR/ -DCMAKE_PREFIX_PATH=../../$Z5_INSTALL_DIR/ ..
cmake -DCMAKE_INSTALL_PREFIX=../../$Z5_INSTALL_DIR/ -DCMAKE_PREFIX_PATH=../../$Z5_INSTALL_DIR/ -DBUILD_CODEC=OFF ..
make install -j4
cd ../../

Expand All @@ -158,6 +158,6 @@ unzip DCMTK-3.6.7.zip
cd dcmtk-DCMTK-3.6.7/
mkdir build_man
cd build_man/
cmake -DCMAKE_INSTALL_PREFIX=../../$Z5_INSTALL_DIR/ -DCMAKE_PREFIX_PATH=../../$Z5_INSTALL_DIR/ -DDCMTK_WITH_ICONV=OFF -DBUILD_SHARED_LIBS=ON ..
cmake -DCMAKE_INSTALL_PREFIX=../../$Z5_INSTALL_DIR/ -DCMAKE_PREFIX_PATH=../../$Z5_INSTALL_DIR/ -DDCMTK_WITH_ICONV=OFF -DBUILD_SHARED_LIBS=ON -DBUILD_APPS=OFF ..
make install -j4
cd ../../
4 changes: 2 additions & 2 deletions ci-utils/install_prereq_win.bat
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ tar -xvf v2.5.0.zip
pushd openjpeg-2.5.0
mkdir build_man
pushd build_man
cmake -DCMAKE_INSTALL_PREFIX=../../local_install/ -DCMAKE_PREFIX_PATH=../../local_install/ ..
cmake -DCMAKE_INSTALL_PREFIX=../../local_install/ -DCMAKE_PREFIX_PATH=../../local_install/ -DBUILD_CODEC=OFF ..
cmake --build . --config Release --target install --parallel 4
popd
popd
Expand All @@ -147,7 +147,7 @@ tar -xvf DCMTK-3.6.7.zip
pushd dcmtk-DCMTK-3.6.7
mkdir build_man
pushd build_man
cmake -DCMAKE_INSTALL_PREFIX=../../local_install/ -DCMAKE_PREFIX_PATH=../../local_install/ -DBUILD_SHARED_LIBS=ON -DDCMTK_WITH_ICONV=OFF -DDCMTK_WITH_TIFF=ON -DWITH_LIBTIFFINC=../../local_install -DDCMTK_WITH_PNG=ON -DWITH_LIBPNGINC=../../local_install -DDCMTK_WITH_ZLIB=ON -DWITH_ZLIBINC=../../local_install -DDCMTK_WITH_OPENJPEG=ON -DWITH_OPENJPEGINC=../../local_install ..
cmake -DCMAKE_INSTALL_PREFIX=../../local_install/ -DCMAKE_PREFIX_PATH=../../local_install/ -DBUILD_SHARED_LIBS=ON -DDCMTK_WITH_ICONV=OFF -DDCMTK_WITH_TIFF=ON -DWITH_LIBTIFFINC=../../local_install -DDCMTK_WITH_PNG=ON -DWITH_LIBPNGINC=../../local_install -DDCMTK_WITH_ZLIB=ON -DWITH_ZLIBINC=../../local_install -DDCMTK_WITH_OPENJPEG=ON -DWITH_OPENJPEGINC=../../local_install -DBUILD_APPS=OFF ..
cmake --build . --config Release --target install --parallel 4
popd
popd
Expand Down
42 changes: 42 additions & 0 deletions src/nyx/nyxus_dicom_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include "dcmtk/dcmjpls/djdecode.h" /* for JPEG-LS decoders */
#include "dcmtk/dcmdata/dcrledrg.h" /* for RLE decoder */
#include "dcmtk/dcmjpeg/dipijpeg.h" /* for dcmimage JPEG plugin */
#include "dcmtk/dcmseg/segdoc.h"
#include "dcmtk/dcmseg/segment.h"
#include "dcmtk/dcmseg/segutils.h"

template<class DataType>
class NyxusGrayscaleDicomLoader : public AbstractTileLoader<DataType>
Expand Down Expand Up @@ -141,6 +144,9 @@ class NyxusGrayscaleDicomLoader : public AbstractTileLoader<DataType>
}
} else {
switch(bitsPerSample_){
case 1:
copyBinaryFrame(*tile, frame_no);
break;
case 8:
copyFrame<uint8_t>(*tile, frame_no);
break;
Expand Down Expand Up @@ -249,6 +255,42 @@ class NyxusGrayscaleDicomLoader : public AbstractTileLoader<DataType>

}

/// @brief Private function to copy and cast the values for Binary Segmentation Image
/// @tparam FileType Type inside the file
/// @param dest_as_vector Feature extraction facing buffer to fill
/// @param frame_no Frame to copy
void copyBinaryFrame(
std::vector<DataType>& dest_as_vector,
uint32_t frame_no)
{
DcmDataset* ds = dcm_ff_.getDataset();
DcmSegmentation *segdoc = nullptr;

OFCondition status = DcmSegmentation::loadDataset(*ds, segdoc);
if(status.good()){
const DcmIODTypes::Frame *frame = segdoc->getFrame(static_cast<size_t>(frame_no));
const DcmIODTypes::Frame *unpacked_frame = nullptr;
unpacked_frame = DcmSegUtils::unpackBinaryFrame(frame, tileHeight_, tileWidth_);
if(unpacked_frame){
if(dest_as_vector.size() < unpacked_frame->length){
std::stringstream message;
message
<< "Tile Loader ERROR: The destination buffer size ("
<<dest_as_vector.size()
<<") is smaller than the frame size ("
<< unpacked_frame->length <<").";
throw (std::runtime_error(message.str()));
}
DataType* dest = dest_as_vector.data();
for(size_t i=0;i<unpacked_frame->length;++i){
*(dest+i) = static_cast<DataType>(unpacked_frame->pixData[i]);
}
delete unpacked_frame;
}
}

}

DcmFileFormat dcm_ff_;
size_t
fullHeight_ = 0, ///< Full height in pixel
Expand Down

0 comments on commit cba754a

Please sign in to comment.