我正在尝试在图像上应用蒙版,但是蒙版图像具有与要屏蔽的图像不同的尺寸。要应用蒙版,我必须确保图像具有相同的尺寸,因此我使用的是ITK PadImageFilter类,但要这样做必须在索引而不是物理坐标中给出填充值。我的程序使我能够在物理坐标中获得两个图像的边界,而不是它们的索引。
ITK有办法获得给定点的相应索引吗?我理解像素和图像尺寸之间的关系,我只想知道是否有一种方法可以在ITK中自动执行。
编辑:以下是我的代码。我知道问题是由于填充边距(x_min,x_max,...)是以物理坐标而不是索引给出的。我怎么能解决这个问题?
typedef unsigned char UcharPixelType;
typedef short ShortPixelType;
const int Dimension = 3;
//Declare readers for both images (which are of different types)
typedef itk::ImageFileReader< ShortImageType > ShortReaderType;
typedef itk::ImageFileReader< UcharImageType > UcharReaderType;
ShortImageType::Pointer imageToBeMasked = ShortImageType::New();
// Setting imageToBeMasked to read the corresponding image
UcharImageType::Pointer maskingImage = UcharImageType::New();
// Do the same for reading the image that will mask the former one.
// Compute the bounds of both images (i.e. physical coordinates)
double* img_bounds = imageToBeMasked->GetBounds();
double* mask_bounds = maskingImage->GetBounds();
// Compute margins needed to pad the masking image
double x_min = abs(img_bounds[0] - mask_bounds[0]);
double x_max = abs(img_bounds[1] - mask_bounds[1]);
double y_min = abs(img_bounds[2] - mask_bounds[2]);
double y_max = abs(img_bounds[3] - mask_bounds[3]);
double z_min = abs(img_bounds[4] - mask_bounds[4]);
double z_max = abs(img_bounds[5] - mask_bounds[5]);
// Declare the padding filter
typedef itk::PadImageFilter< UcharImageType, UcharImageType > PadFilterType;
PadFilterType::Pointer l_enlarge_mask = PadFilterType::New();
l_enlarge_mask->SetInput(maskingImage->GetOutput());
// Create indexes for giving padding margins to the filter,
// But these are physical coordinates! How to convert them?
UcharImageType::IndexType indexMin;
indexMin[0] = x_min;
indexMin[1] = y_min;
indexMin[2] = z_min;
UcharImageType::IndexType indexMax;
indexMax[0] = x_max;
indexMax[1] = y_max;
indexMax[2] = z_max;
l_enlarge_mask->SetPadLowerBound(indexMin);
l_enlarge_mask->SetPadUpperBound(indexMax);
typedef itk::ImageFileWriter< UcharImageType > UcharWriterType;
UcharWriterType l_writer = UcharWriterType::New();
l_writer->SetInput(l_enlarge_mask->GetOutput());
l_writer->SetFileName("padded_mask.mhd");
try{
l_writer->Update();
catch(itk::ExceptionObject& err) {
std::cerr << "Exception caught!" << err.what() << std::endl;
} // Error: boundary condition is ITK_NULLPTR
我也试图做相反的事情,即在要屏蔽的图像上计算感兴趣的视图(VOI)(因此“裁剪”最大的图像而不是填充最小的图像)。因此,我将掩蔽图像的尺寸作为VOI边界,但是得到的图像总是比给定边界更大(1或2个体素)的几个体素,我不知道为什么。认为这可能是因为两个图像之间的类型不同,但计算屏蔽图像在其版本化版本上的边界也不能解决问题。