VTK读取CT数据

#VTK读取CT数据中的Pixel data
头文件

#include <io.h>  
#include <iostream>  
#include <vector> 
#include <vtkSmartPointer.h>
#include <vtkImageViewer2.h>
#include <vtkImageCast.h>
#include <vtkDICOMImageReader.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkImageData.h>
#include <vtkCoordinate.h>

readDicom.cpp

void getFiles(string path, vector<string>& files) {
    
    intptr_t hFile = 0;
    
    struct _finddata_t fileinfo;
    string p;  //Store path
    if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
    {
        do
        {
            //如果是目录,迭代之(即文件夹内还有文件夹)  
            if ((fileinfo.attrib & _A_SUBDIR))
            {
                //文件名不等于"."&&文件名不等于".."
                //.表示当前目录
                //..表示当前目录的父目录
                //判断时,两者都要忽略,不然就无限递归跳不出去了!
                if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
                    getFiles(p.assign(path).append("\\").append(fileinfo.name), files);
            }
            //如果不是,加入列表  
            else
            {
                files.push_back(p.assign(path).append("\\").append(fileinfo.name));
            }
        } while (_findnext(hFile, &fileinfo) == 0);
        //_findclose函数结束查找
        _findclose(hFile);
    }
}


int str2int(string a, int len) {
    /*string tmp = "D:\\data\\LungPoint\\13\\13\\14\\dcm\\1.2.840.113619.2.428.3.695552.35.1623805458.976.399";

    int n = tmp.size() - 3;*/
    //cout << n << endl;
    //const int n = len;
    int result = 0;
    for (int i = 0; i != a.size() - len; ++i) {

        int bb = *(a.end() - 1 - i) - '0';
        result += bb * int(pow(10, i));
    }
    return result;
}



void dicomread(vector<string> FileName_List) {
    
    const int threshold = 800;
    //vector<string> index;
    vector<Tuple> Index_list;
    float slice = 1;



    vtkDICOMImageReader* reader = vtkDICOMImageReader::New();
    const char *path = FileName_List[0].c_str();
    reader->SetFileName(path);                         //read dcm data

    //reader->SetFileName("lena.bmp");    
    reader->Update();

    double spaceing[3];
    reader->GetOutput()->GetSpacing(spaceing);
    std::cout << "parameter:" << spaceing[0] << " " 
        << spaceing[1] << " " << spaceing[2] << std::endl;

    thick = spaceing[2];      
    space = spaceing[0];   





    int sum = 0;
    int max = 0;
    for (auto it : FileName_List) {
        //cout << it << endl;
        const DicomImage dcm_image(it.c_str());
        const auto rows = dcm_image.getHeight();     
        const auto cols = dcm_image.getWidth();      
        /*cout << "rows: " << rows << " ";
        cout << "cols: " << cols << endl;*/

        DcmFileFormat file_format;
        const auto condition = file_format.loadFile(it.c_str());
        DcmDataset* data_set = file_format.getDataset();

        const E_TransferSyntax xfer = data_set->getOriginalXfer();
        // decompress data set if compressed
        data_set->chooseRepresentation(xfer, nullptr);
        // data_set->chooseRepresentation(EXS_LittleEndianExplicit, nullptr);

        DcmElement* element = nullptr;
        OFCondition result = data_set->findAndGetElement(DCM_PixelData, element);
        
        unsigned short* pix_data;
        result = element->getUint16Array(pix_data);
        signed short* data = nullptr;
        signed short int b = 0;
        
        //Threshold selection
        for (int i = rows; i < rows; i++) {
            // could use dst2.at<unsigned short>(i, j) = ?
           
            for (int j = 0; j < cols; j++) {
                auto temp = pix_data[i * cols + j];
                


                
            }
            //cout << endl;
        }
        //cout << endl;
    //    
     

    }
   

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值