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

DICOM: add null imageIO handler to allow parsing of DICOM data even with unsupported transfer syntax #2767

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
25 changes: 17 additions & 8 deletions core/file/dicom/mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "header.h"
#include "phase_encoding.h"
#include "image_io/null.h"
#include "image_io/default.h"
#include "image_io/mosaic.h"
#include "image_io/variable_scaling.h"
Expand Down Expand Up @@ -68,6 +69,8 @@ namespace MR {
// build up sorted list of frames:
vector<Frame*> frames;

bool transfer_syntax_supported = true;

// loop over series list:
for (const auto& series_it : series) {
try {
Expand All @@ -82,13 +85,9 @@ namespace MR {

// loop over images in each series:
for (auto image_it : *series_it) {
if (!image_it->transfer_syntax_supported) {
Exception E ("unsupported transfer syntax found in DICOM data");
E.push_back ("consider using third-party tools to convert your data to standard uncompressed encoding");
E.push_back ("See the MRtrix3 documentation on DICOM handling for details:");
E.push_back (" http://mrtrix.readthedocs.io/en/latest/tips_and_tricks/dicom_handling.html#error-unsupported-transfer-syntax");
throw E;
}
if (!image_it->transfer_syntax_supported)
transfer_syntax_supported = false;

// if multi-frame, loop over frames in image:
if (image_it->frames.size()) {
std::sort (image_it->frames.begin(), image_it->frames.end(), compare_ptr_contents());
Expand Down Expand Up @@ -209,7 +208,7 @@ namespace MR {
}

size_t nchannels = image.samples_per_pixel;
if (nchannels == 1 && !image.frames.size()) {
if (nchannels == 1 && !image.frames.size() && transfer_syntax_supported) {
// only guess number of samples per pixel if not explicitly set in
// DICOM and not using multi-frame:
nchannels = image.data_size / (frame.dim[0] * frame.dim[1] * (frame.bits_alloc/8));
Expand Down Expand Up @@ -363,6 +362,16 @@ namespace MR {
}


if (!transfer_syntax_supported) {
WARN ("unsupported transfer syntax found in DICOM data");
WARN ("consider using third-party tools to convert your data to standard uncompressed encoding");
WARN ("See the MRtrix3 documentation on DICOM handling for details:");
WARN (" http://mrtrix.readthedocs.io/en/latest/tips_and_tricks/dicom_handling.html#error-unsupported-transfer-syntax");

io_handler.reset (new MR::ImageIO::Null (H));
return io_handler;
}

if (image.images_in_mosaic) {

INFO ("DICOM image \"" + H.name() + "\" is in mosaic format");
Expand Down
34 changes: 34 additions & 0 deletions core/image_io/null.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* Copyright (c) 2008-2023 the MRtrix3 contributors.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Covered Software is provided under this License on an "as is"
* basis, without warranty of any kind, either expressed, implied, or
* statutory, including, without limitation, warranties that the
* Covered Software is free of defects, merchantable, fit for a
* particular purpose or non-infringing.
* See the Mozilla Public License v. 2.0 for more details.
*
* For more details, see http://www.mrtrix.org/.
*/

#include "image_io/null.h"
#include "header.h"

namespace MR {
namespace ImageIO {

void Null::load(const Header &header, size_t) {
throw Exception("No suitable handler to access data in \"" + header.name() +
"\"");
}

void Null::unload(const Header &header) {
throw Exception("No suitable handler to access data in \"" + header.name() +
"\"");
}

} // namespace ImageIO
} // namespace MR
38 changes: 38 additions & 0 deletions core/image_io/null.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* Copyright (c) 2008-2023 the MRtrix3 contributors.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Covered Software is provided under this License on an "as is"
* basis, without warranty of any kind, either expressed, implied, or
* statutory, including, without limitation, warranties that the
* Covered Software is free of defects, merchantable, fit for a
* particular purpose or non-infringing.
* See the Mozilla Public License v. 2.0 for more details.
*
* For more details, see http://www.mrtrix.org/.
*/

#ifndef __image_io_null_h__
#define __image_io_null_h__

#include "image_io/base.h"

namespace MR {
namespace ImageIO {

class Null : public Base {
NOMEMALIGN
public:
Null(const Header &header) : Base(header) {}

protected:
virtual void load(const Header &, size_t);
virtual void unload(const Header &);
};

} // namespace ImageIO
} // namespace MR

#endif