View difference between Paste ID: G2Hirxbb and PArvffSq
SHOW: | | - or go back to the newest paste.
1
#include "itkImage.h"
2
#include "itkImageFileWriter.h"
3
#include "itkImageFileReader.h"
4
#include "itkMinimumMaximumImageCalculator.h"
5
#include "itkImageRegionIterator.h"
6
#include <iostream>
7
#include <string>
8
#include <stdlib.h>
9
#include <fstream>
10
11
using namespace std;
12
13-
const unsigned int RDImageDimension = ImageDimension-1;
13+
14
typedef double  PixelType; 
15
typedef itk::Image< PixelType, ImageDimension > ImageType;
16-
typedef itk::Image< PixelType, RDImageDimension> RDImageType;
16+
17
typedef itk::ImageFileWriter< ImageType > WriterType;
18
19-
ofstream file;
19+
20
{
21-
void writetofile(PixelType min, PixelType max)
21+
22
	typedef itk::MinimumMaximumImageCalculator <ImageType> 	ImageCalculatorFilterType;
23-
	file << min << " " << max << std::endl;
23+
24
	
25
	imageCalculatorFilter->SetImage( inputimage );
26
	imageCalculatorFilter->Compute();
27
28
	PixelType Imin = imageCalculatorFilter->GetMinimum();
29
	PixelType Imax = imageCalculatorFilter->GetMaximum();
30
	PixelType Omin = 0; 
31
	PixelType Omax = 1;
32-
	double pi = 4.0*atan(1.0);
32+
33-
	double U = rand()/float(RAND_MAX); double V = rand()/float(RAND_MAX);
33+
	typedef itk::ImageRegionIterator< ImageType > IteratorType;
34-
	double X = sqrt(-2*log(U))*cos(2*pi*V);
34+
	IteratorType imageIterator(inputimage,iterregion);
35-
	double Y = sqrt(-2*log(U))*sin(2*pi*V);
35+
36-
	double randomnumber = (Y*Y + 0.1)*(X/abs(X));
36+
37
38
	std::cout << "image iterator at end?" << imageIterator.IsAtEnd() << std::endl; //gives 1 always
39
40
	while(!imageIterator.IsAtEnd())
41-
	std::cout << 25*randomnumber << std::endl;
41+
42
		PixelType inputPixel = imageIterator.Get();
43-
	PixelType Omin = 25*randomnumber;
43+
		PixelType outputPixel = (inputPixel-Imin)*((Omax-Omin)/(Imax-Imin))+Omin;
44-
	PixelType Omax = 255-Omin;
44+
45
		++imageIterator;
46
	}
47-
	writetofile(Imin, Imax);
47+
48
	ImageType::Pointer outputimage = inputimage;
49-
	itk::ImageRegionIterator<ImageType> imageIterator(inputimage,iterregion);
49+
50-
	PixelType outputPixel;
50+
51-
	PixelType inputPixel;
51+
52
53
int main(int argc , char *argv[])
54
{
55
	if( argc < 3 )
56
	{
57
		std::cerr << "Usage: " << std::endl;
58
		std::cerr << argv[1] << " inputImageFile" << std::endl;
59-
		inputPixel = imageIterator.Get();
59+
60-
		outputPixel = (inputPixel-Imin)*((Omax-Omin)/(Imax-Imin))+Omin;
60+
61
	}
62
63
	ReaderType::Pointer	reader = ReaderType::New();
64
65
	reader->SetFileName(argv[1]);
66
	reader->Update();
67
68
	ImageType::Pointer image = reader->GetOutput();
69
	ImageType::RegionType region = image->GetLargestPossibleRegion();
70
	ImageType::SizeType size = region.GetSize();
71
72-
	//srand(0);
72+
73-
	file.open("minmax.txt");
73+
74
75
	int nrofloops = size[ImageDimension-1];
76
77
	size[ImageDimension-1] = 0;
78
79
	region.SetSize(size);
80
81
	ImageType::Pointer scaledImage;
82
	scaledImage = image;
83
84
	for(int i=0; i < nrofloops; i++)
85
	{
86
		volumestart[ImageDimension-1] = i;
87
		region.SetIndex(volumestart);
88
		//PixelType max = Imaxvector.get(i);
89
		scaledImage = randomscaler(scaledImage, max, region, scalingback);			
90
	}
91
92
	return 0;
93
}