您的位置:首页 > 其它

ITK 读取三维的mha 如何遍历像素值 以及对mha 图像的小认识

2015-01-15 09:42 465 查看
itk自带的mha图像

BrainProtonDensity3Slices.mha mha图像可以用文本文件打开

NDims = 3

DimSize = 181 217 3

ElementType = MET_UCHAR

ElementSpacing = 1.0 1.0 1.0

ElementByteOrderMSB = False

ElementDataFile = BrainProtonDensity3Slices.raw

这就是打开存储的信息ElementDataFile = BrainProtonDensity3Slices.raw

根据这个我们知道这个像素数据是存储在BrainProtonDensity3Slices.raw这个里边。所以我们读取mha的时候一定要有下边那个文件

有时候也有可能是ElementDataFile = LOCAL哪就只有一个mha文件我们就可以读取

BrainProtonDensity3Slices.raw

代码如下:希望了以帮到大家

std::string inputFilename;
typedef itk::Image< unsigned char,3>  ImageType;
typedef itk::ImageFileReader<ImageType> ReaderType;
inputFilename = "C:\\Users\\Administrator\\Desktop\\TAM088_1.mha";
ReaderType::Pointer reader=ReaderType::New();
reader->SetFileName(inputFilename);
reader->Update();
ImageType::Pointer image=reader->GetOutput();
ImageType::SizeType size=image->GetLargestPossibleRegion().GetSize();

ImageType::IndexType index={{188,283,20}};
ImageType::PixelType value=image->GetPixel(index);
printf("%uc",value);

for(int x=0;x<size[0];x++)
{
for(int y=0;y<size[1];y++)
{
for(int z=0;z<size[2];z++)
{

index[0]=x;
index[1]=y;
index[2]=z;
value=image->GetPixel(index);
printf("%uc ",value);
//M.at<unsigned char>(x,y,z)=value;
//M.at<unsigned char>(x,y,z)=image->GetPixel(index);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: