InputImageType::Pointer getEmpty(int s1,int s2, int s3)
{
	InputImageType::Pointer p = InputImageType::New();
	InputImageType::SizeType size;
	InputImageType::IndexType index;
	InputImageType::RegionType region;
	size[0] = s1; size[1] = s2; size[2] = s3;
	index.Fill(0);
	region.SetSize(size);
	region.SetIndex(index);
	p->SetRegions(region);
	p->Allocate();
	return p;
}
Beispiel #2
0
void segmentation::on_retinalLayerSegButton_clicked()
{
    fstream fin1, fin7, fin11, fin12; 
    char* s1Txt = ("../data/ped/txt/15715_1.txt");//s1.txt
    char* s7Txt = ("../data/ped/txt/15715_7.txt"); 
    char* s11Txt = ("../data/ped/txt/15715_11.txt"); 
    char* s12Txt = ("../data/ped/txt/15715_12.txt");
    //这样开辟内存容易出现堆栈溢出问题, 选择new & delete
    //int s1[64][512], s7[64][512], s11[64][512], s12[64][512]; 
    int (*s1)[512] = new int [64][512];
    int (*s7)[512] = new int [64][512];
    int (*s11)[512] = new int [64][512];
    int (*s12)[512] = new int [64][512];
    fin1.open(s1Txt, ios::in);
    fin7.open(s7Txt, ios::in);
    fin11.open(s11Txt, ios::in);
    fin12.open(s12Txt, ios::in);
    for(int z=0; z<64; z++)
    {
        for(int x=0; x<512; x++)
        {
            fin1>>s1[z][x];
            fin7>>s7[z][x];
            fin11>>s11[z][x];
            fin12>>s12[z][x];
        }
    }
    fin1.close();
    fin7.close();
    fin11.close();
    fin12.close();

    typedef itk::Image<unsigned short,3>InputImageType; 
    typedef itk::Image<unsigned short,3>OutputImageType; 
    InputImageType::Pointer inputImage = InputImageType::New();
    InputImageType::Pointer outputImage = InputImageType::New();
    typedef itk::ImageFileReader<InputImageType>ReaderType;
    ReaderType::Pointer reader = ReaderType::New();
    reader->SetFileName(inputFileName); 
    reader->Update();
    inputImage = reader->GetOutput();
    InputImageType::IndexType voxelIndex;
    InputImageType::SizeType imgSize = inputImage->GetLargestPossibleRegion().GetSize();
    OutputImageType::IndexType index;
    index[0]=0;
    index[1]=0;
    index[2]=0;
    OutputImageType::SizeType size;
    size[0]=imgSize[0];
    size[1]=imgSize[1];
    size[2]=imgSize[2];  
    //create a region for enhance result
    OutputImageType::RegionType region;
    region.SetIndex(index);
    region.SetSize(size);
    outputImage->SetRegions(region);
    outputImage->Allocate();
    //make four surfaces into a MHD file
    for(int z = 0; z < imgSize[2]; z++)
        for(int y = 0; y < imgSize[1]; y++)
            for(int x = 0; x < imgSize[0]; x++)
            {
                voxelIndex[0] = x;
                voxelIndex[1] = y;
                voxelIndex[2] = z;
                if(y == s1[z][x])
                {
                    inputImage->SetPixel(voxelIndex, 65535);
                }
                if(y == s7[z][x])
                {
                    inputImage->SetPixel(voxelIndex, 65535);
                }
                if(y == s11[z][x])
                {
                    inputImage->SetPixel(voxelIndex, 65535);
                }
                if(y == s12[z][x])
                {
                    inputImage->SetPixel(voxelIndex, 65535);
                }
            }
            delete []s1;//释放内存
            delete []s7;
            delete []s11;
            delete []s12;

            //文件前缀名
            filePrefix = inputFileName;//char* to string
            filePrefix = filePrefix.substr(0, filePrefix.length() - 4);
            filePrefix = filePrefix + "_layerSeg.mhd";
            strcpy(outputFileName, filePrefix.c_str());//string to char*
            typedef itk::ImageFileWriter<OutputImageType>WriterType;
            WriterType::Pointer writer = WriterType::New();
            writer->SetFileName(outputFileName);
            writer->SetInput(inputImage);
            writer->Update();
            emit returnOutputFileName(outputFileName);//发出信号
}
Beispiel #3
0
InputImageType::Pointer Curvelet::RunOnInputImage(InputImageType::Pointer InputImage)
{
	//InputImage = NewInputImage;
	slices = InputImage->GetLargestPossibleRegion().GetSize()[2];
	InputImageType::Pointer outputim = InputImageType::New();
	outputim->SetRegions(InputImage->GetLargestPossibleRegion());
	outputim->Allocate();
	FloatImageType::Pointer cosim = FloatImageType::New();
	cosim->SetRegions(InputImage->GetLargestPossibleRegion());
	cosim->Allocate();
	FloatImageType::Pointer sinim = FloatImageType::New();
	sinim->SetRegions(InputImage->GetLargestPossibleRegion());
	sinim->Allocate();

	if(outputim->GetBufferPointer() == NULL || cosim->GetBufferPointer() == NULL || sinim->GetBufferPointer() == NULL)
	{
		printf("Couldnt' allocate memory - 3.. going to crash now\n");
	}
	int max_dim = tile_size;


	int xsize = InputImage->GetLargestPossibleRegion().GetSize()[0];
	int ysize = InputImage->GetLargestPossibleRegion().GetSize()[1];

	int kx = 0;int ky = 0;


	kx = xsize /(max_dim-this->border);
	ky = ysize /(max_dim-this->border);

	int remx = xsize % (max_dim-this->border);
	int remy = ysize % (max_dim-this->border);

	if ( remx > 0 )
		kx ++;
	if ( remy > 0 )
		ky ++;

	for(int xco = 0; xco < kx; xco++)
	{
		for(int yco = 0; yco < ky; yco++)
		{

			InputImageType::SizeType imsize = InputImage->GetLargestPossibleRegion().GetSize();
			InputImageType::IndexType index;
			InputImageType::SizeType size;
			InputImageType::RegionType region;

			index.Fill(0);
			size[0] =  MIN((xco)*(max_dim-this->border)+max_dim-1,imsize[0]-1) -  xco * (max_dim-this->border) +1;
			size[1] =  MIN((yco)*(max_dim-this->border)+max_dim-1,imsize[1]-1) -  yco * (max_dim-this->border) +1;
			size[2] = imsize[2];

			InputImageType::Pointer imtile = InputImageType::New();
			region.SetIndex(index);
			region.SetSize(size);
			imtile->SetRegions(region);
			imtile->Allocate();
			if(imtile->GetBufferPointer()==NULL)
				printf("Couldn't allocate memory - 4 .. going to crash now\n");
			InputImageType::RegionType region1;
			index[0] = xco *(max_dim-this->border);
			index[1] = yco *(max_dim-this->border);
			index[2] = 0;
			region1.SetIndex(index);
			region1.SetSize(size);

			typedef itk::ImageRegionIterator<InputImageType> IteratorType;
			IteratorType iter1(InputImage,region1);
			IteratorType iter2(imtile,region);


			//printf("xco = %d yco = %d :\n",xco,yco);
			region1.Print(std::cout);
			region.Print(std::cout);

			iter1.GoToBegin();
			iter2.GoToBegin();
			for(;!iter1.IsAtEnd();++iter1,++iter2)
			{
				iter2.Set(iter1.Get());
			}


			InputImageType::Pointer outputtile = InputImageType::New();
			outputtile->SetRegions(imtile->GetLargestPossibleRegion());
			outputtile->Allocate();
			FloatImageType::Pointer cosimtile = FloatImageType::New();
			cosimtile->SetRegions(imtile->GetLargestPossibleRegion());
			cosimtile->Allocate();
			FloatImageType::Pointer sinimtile = FloatImageType::New();
			sinimtile->SetRegions(imtile->GetLargestPossibleRegion());
			sinimtile->Allocate();
			if(outputtile->GetBufferPointer() == NULL || cosimtile->GetBufferPointer()==NULL || sinimtile->GetBufferPointer() == NULL )
			{
				printf("Couldn't allocate memory - 5 .. going to crash now ..\n");
			}

			{
#pragma omp parallel for shared(cosimtile,imtile,sinimtile,outputtile)  num_threads(numt)
				for(int counter = 0; counter < slices; counter++)
				{
					//printf("Counter = %d\n",counter);
					Input2DImageType::Pointer im2d = getSlice(imtile,counter);
					Input2DImageType::Pointer om2d;
					Float2DImageType::Pointer cosim2d,sinim2d;
					//call single slice 2-d curvelets function
					getCurveletsForOneSlice(im2d,om2d,cosim2d,sinim2d);
					copyslice<InputPixelType>(om2d,outputtile,counter);
					copyslice<float>(cosim2d,cosimtile,counter);
					copyslice<float>(sinim2d,sinimtile,counter);
				}
			}
			
			//printf("copying the tile\n");
			if(xco != 0)
			{
				size[0] = size[0] - border/2;
				index[0] = border/2;
			}
			if(xco != kx-1)
			{
				size[0] = size[0] - border/2;
			}

			if(yco != 0)
			{
				size[1] = size[1] - border/2;
				index[1] = border/2;
			}
			if(yco != ky-1)
			{
				size[1] = size[1] - border/2;
			}
			size[2] = slices;
			index[2] = 0;


			region.SetIndex(index);
			region.SetSize(size);
			
			if(xco!=0)
			{
				index[0] = xco *(max_dim-border)+border/2;
			}
			if(yco!=0)
			{
				index[1] = yco *(max_dim-border)+border/2;
			}
			
			
			index[2] = 0;
			region1.SetSize(size);
			region1.SetIndex(index);

			iter1 = IteratorType(outputim,region1);
			iter2 = IteratorType(outputtile,region);
			typedef itk::ImageRegionIterator<FloatImageType> FIteratorType;
			FIteratorType iter3(cosim,region1);
			FIteratorType iter4(cosimtile,region);
			FIteratorType iter5(sinim,region1);
			FIteratorType iter6(sinimtile, region);

			iter1.GoToBegin();iter2.GoToBegin();
			iter3.GoToBegin();iter4.GoToBegin();
			iter5.GoToBegin();iter6.GoToBegin();

			for(;!iter1.IsAtEnd();++iter1,++iter2,++iter3,++iter4,++iter5,++iter6)
			{
				iter1.Set(iter2.Get());
				iter3.Set(iter4.Get());
				iter5.Set(iter6.Get());
			}
			//printf("Done with copying the tile to full image\n");
		}
	}
	return outputim;
}