2015-10-26 201 views
2

訪問itk :: LabelObject的像素列表時遇到問題。 使用itk :: OrientedBoundingBoxLabelObject(https://github.com/blowekamp/itkOBBLabelMap)獲得此LabelObject。原始的3D圖像是一個CBCT Dicom,我正在尋找一個小矩形標記的位置和方向。ITK從itk獲取像素列表:: LabelObject

這是導致獲取代碼ITK :: LabelObject:

typedef short LabelPixelType; 
typedef itk::LabelMap<LabelObjectType> LabelMapType; 
typedef itk::OrientedBoundingBoxLabelMapFilter<LabelMapType> OBBLabelMapFilter; 

typename OBBLabelMapFilter::Pointer toOBBLabelMap = OBBLabelMapFilter::New(); 
typename ToLabelMapFilterType::Pointer toLabelMap = ToLabelMapFilterType::New(); 

toOBBLabelMap->SetInput(toLabelMap->GetOutput()); 
toOBBLabelMap->Update(); 

LabelObjectType* labelObject = toOBBLabelMap->GetOutput()->GetNthLabelObject(idx); 
OBBSize = labelObject->GetOrientedBoundingBoxSize(); 

我猜訪問像素座標是可能的,因爲它要訪問的某種方式,以計算邊界框,但到目前爲止我還沒有做到這一點。然後我嘗試將itk :: LabelMap(或LabelObject直接)轉換爲二進制圖像,我可以更輕鬆地獲取像素。並用VTK轉換並顯示這個markerBinaryImage,而沒有更多的結果(我得到一個黑色的圖像)。

typedef itk::LabelMapToBinaryImageFilter<LabelMapType, ImageType> LabelMapToBinaryImageFilterType; 
LabelMapToBinaryImageFilterType::Pointer labelImageConverter = LabelMapToBinaryImageFilterType::New(); 
labelImageConverter->SetInput(toLabelMap->GetOutput()); 
labelImageConverter->Update(); 
ImageType::Pointer markerBinaryImage = labelImageConverter->GetOutput(); 

有沒有人有關於如何到這個像素列表的想法?

回答

2

你可能不喜歡這樣:在從Insight雜誌文章Label object representation and manipulation with ITK獲得

for(unsigned int i = 0; i < filter->GetOutput()->GetNumberOfLabelObjects(); ++i) { 
    //Obtain the ith label object 
    FilterType::OutputImageType::LabelObjectType* labelObject = 
     filter->GetOutput()->GetNthLabelObject(i); 

    //Then, you may obtain the pixels of each label object like this: 
    for(unsigned int pixelId = 0; pixelId < labelObject->Size(); pixelId++) { 
     std::cout << labelObject->GetIndex(pixelId); 
    } 
} 

此信息。在那裏,它說你可以直接使用Region屬性來獲得邊界框。我沒有找到ITK :: LabelObject獲得區域的方式,但這裏是itk::LabelObject的繼承圖:

Inheritance diagram of LabelObject

如果你的標籤對象是itk::ShapeLabelObject類型的,你可以使用GetBoundingBox()方法來獲得邊界框。它還有其他許多值得關注的方法。

我試圖然後轉換itk :: LabelMap(...)沒有更多的結果(我得到一個黑色的圖像)。

這裏有一條建議,不要試試這個複雜的東西來驗證其他複雜的東西。你可能在連鎖店的其他地方失敗。相反,像我之前說的那樣讀取像素並檢查數據。好看!

+0

謝謝你,我設法得到這個像素列表,感謝您的建議。我不直接使用region屬性的原因是它只給出了一個軸對齊的邊界框,我需要一個定向的邊界框。這個OBB過濾器雖然運行良好。 –

+0

是的。 :)歡迎來到AABB問題俱樂部!很高興工作! –