资源简介

本资源是将DICOM格式的CT图用VTK读取,转给OpenCV处理并可视化。当中的操作比普通的图片显示要更困难(可看我的博文了解)。本程序只要配置好OpenCV和VTK环境即可成功运行,使用简单方便。

资源截图

代码片段和文件信息

#include 
#include   // 当中含有_finddata_t
#include 
#include 

#include 
#include 
#include 

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
using namespace cv;

// 读入一个CT图,返回它的像素矩阵,使用OpenCV的Mat类型返回
void dicomread(string inputFilename Mat &imgvtkSmartPointer &reader)
{
    img.create(512512CV_32SC1); 

vtkSmartPointer imageCast = 
vtkSmartPointer::New();

    reader->SetFileName(inputFilename.c_str());

    reader->Update();

imageCast->SetInputConnection(reader->GetOutputPort());
imageCast->SetOutputScalarTypeToInt();
imageCast->Update();

// 图像的基本信息
int dims[3];
reader->GetOutput()->GetDimensions(dims);

//图像的像素值
for(int k=0;k {
    for(int j=0;j {
    for(int i=0;i {
    int* pixel = 
(int*)(imageCast->GetOutput()->GetScalarPointer(ijk)); // 第i列第j行的像素值
img.at(ji) = int(*pixel); // 第j行第i列的像素值
}
}
}
}

void showdicom(Mat I)
{
double maxx=0minn=0;
    double *max = &maxx;
double *min = &minn;
I.convertTo(ICV_64FC1);
minMaxIdx(Iminmax);
for(int i=0;i {
    for(int j=0;j {
    I.at(ij) = 255*(I.at(ij)-minn)*1/(maxx-minn);
}
}

minMaxIdx(Iminmax);
for(int i=0;i {
for(int j=0;j I.at(ij) = (I.at(ij)-minn)*1/(maxx-minn);
}
//cout << I < imshow(“DICOM Image“I);
waitKey(0);
}

int main()
{
    string filename = “D:\\CT\\CT000895“;
    Mat I1G1;
    vtkSmartPointer reader = 
vtkSmartPointer::New();
    // 读入dicom图
dicomread(filenameI1reader);
flip(I1I10);
//cout << I1.channels() << “  “ << I1.size() << endl;
showdicom(I1);
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件      526948  2011-09-03 01:04  DicomReader\CT000895
     文件        2257  2017-06-21 10:55  DicomReader\dicomreader.cpp
     目录           0  2017-06-21 10:56  DicomReader\

评论

共有 条评论