Как я могу дополнить изображение, когда я знаю только его физические границы?

Я пытаюсь нанести маску на изображение, но маскирующее изображение имеет другие размеры, чем маскируемое. Чтобы применить маску, я должен убедиться, что изображения имеют одинаковые размеры, поэтому я использую класс 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 вокселя), чем данные границы, и я понятия не имею, почему. Предполагалось, что это может быть из-за разницы типов между двумя изображениями, но вычисление границ маскирующего изображения в его отлитой версии также не решает проблему.

3

Решение

Что вам нужно TransformPhysicalPointToIndex и друзья. Эти методы являются частью ImageBase учебный класс.

2

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]