簡體   English   中英

如何使用 GDCM 逐片寫入體素數據?

[英]How to use GDCM to write voxel data, slice by slice?

在我為 GDCM 看到的所有關於如何寫入圖像數據的示例中,他們總是將圖像卷視為一個整體的、有凝聚力的緩沖區。 基本結構沿線

#include "gdcmImage.h"
#include "gdcmImageWriter.h"
#include "gdcmFileDerivation.h"
#include "gdcmUIDGenerator.h"

int write_image(...)
{
  size_t width = ..., height = ..., depth = ...;
  auto im = new gdcm::Image;

  std::vector<...> buffer;
  auto p = buffer.data();

  im->SetNumberOfDimensions(3);
  im->SetDimension(0, width);
  im->SetDimension(1, height);
  im->SetDimension(1, depth);

  im->GetPixelFormat().SetSamplesPerPixel(...);
  im->SetPhotometricInterpretation( gdcm::PhotometricInterpretation::... );

  unsigned long l = im->GetBufferLength();
  if( l != width * height * depth * sizeof(...) ){ return SOME_ERROR; }
  gdcm::DataElement pixeldata( gdcm::Tag(0x7fe0,0x0010) );
  pixeldata.SetByteValue( buffer.data(), buffer.size()*sizeof(*buffer.data()) );
  im->SetDataElement( pixeldata );

  gdcm::UIDGenerator uid;
  auto file = new gdcm::File;

  gdcm::FileDerivation fd;
  const char UID[] = ...;
  fd.AddReference( ReferencedSOPClassUID, uid.Generate() );
  fd.SetFile( *file );
  // If all Code Value are ok the filter will execute properly
  if( !fd.Derive() ){ return SOME_ERROR; }

  gdcm::ImageWriter w;
  w.SetImage( *im );
  w.SetFile( fd.GetFile() );

  // Set the filename:
  w.SetFileName( "some_image.dcm" );
  if( !w.Write() ){ return SOME_ERROR; }

  return 0;
}

我使用這種方法面臨的問題是,如果正在制作額外的副本,我需要存儲的圖像數據量很容易超過可用系統 memory; 具體來說,這些是 4096×4096×2048 個 12 位體素的體積,因此 memory 中的數據約為 48GiB。

但是,使用gdcm::DataElementgdcm::Image::SetDataElement的方法顯然會在buffer中創建數據的完整副本,這很麻煩。 一方面,我的成像系統產生的數據並不作為一個有凝聚力的奇異值塊存在於 memory 中; 它被分成幾片。 並且數據總量適合僅使用一次的系統的 memory。

對我來說,逐片讀取數據是微不足道的,這將顯着降低 memory 要求。 但是我很茫然,如何使用 GDCM 來完成。

你檢查過 gdcm::FileStreamer:

參見典型設置:

該示例展示了如何創建一個 memory 私有元素,但您可以對公共 DataElement 執行相同操作。

讀取像素數據以塊的形式寫入的更復雜示例是:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM