SHOW:
|
|
- or go back to the newest paste.
1 | - | #include "itkImage.h" |
1 | + | |
2 | - | #include "itkImageFileWriter.h" |
2 | + | |
3 | - | #include "itkImageFileReader.h" |
3 | + | |
4 | - | #include "itkMinimumMaximumImageCalculator.h" |
4 | + | |
5 | - | #include "itkImageRegionIterator.h" |
5 | + | |
6 | - | #include <iostream> |
6 | + | |
7 | - | #include <string> |
7 | + | |
8 | - | #include <stdlib.h> |
8 | + | |
9 | - | #include <fstream> |
9 | + | |
10 | PixelType Imax = imageCalculatorFilter->GetMaximum(); | |
11 | - | using namespace std; |
11 | + | |
12 | PixelType Omax = 1; | |
13 | - | const unsigned int ImageDimension = 4; |
13 | + | |
14 | - | typedef double PixelType; |
14 | + | |
15 | - | typedef itk::Image< PixelType, ImageDimension > ImageType; |
15 | + | |
16 | - | typedef itk::ImageFileReader< ImageType > ReaderType; |
16 | + | |
17 | - | typedef itk::ImageFileWriter< ImageType > WriterType; |
17 | + | |
18 | ||
19 | std::cout << "image iterator at end?" << imageIterator.IsAtEnd() << std::endl; //gives 1 always | |
20 | ||
21 | while(!imageIterator.IsAtEnd()) | |
22 | { | |
23 | PixelType inputPixel = imageIterator.Get(); | |
24 | PixelType outputPixel = (inputPixel-Imin)*((Omax-Omin)/(Imax-Imin))+Omin; | |
25 | imageIterator.Set(outputPixel); | |
26 | ++imageIterator; | |
27 | } | |
28 | ||
29 | ImageType::Pointer outputimage = inputimage; | |
30 | ||
31 | return outputimage; | |
32 | } | |
33 | ||
34 | int main(int argc , char *argv[]) | |
35 | { | |
36 | if( argc < 3 ) | |
37 | { | |
38 | std::cerr << "Usage: " << std::endl; | |
39 | std::cerr << argv[1] << " inputImageFile" << std::endl; | |
40 | std::cerr << argv[2] << " outputImageFile" << std::endl; | |
41 | return EXIT_FAILURE; | |
42 | } | |
43 | ||
44 | ReaderType::Pointer reader = ReaderType::New(); | |
45 | ||
46 | reader->SetFileName(argv[1]); | |
47 | reader->Update(); | |
48 | ||
49 | ImageType::Pointer image = reader->GetOutput(); | |
50 | ImageType::RegionType region = image->GetLargestPossibleRegion(); | |
51 | ImageType::SizeType size = region.GetSize(); | |
52 | ||
53 | ImageType::IndexType volumestart; | |
54 | volumestart = image->GetLargestPossibleRegion().GetIndex(); | |
55 | ||
56 | int nrofloops = size[ImageDimension-1]; | |
57 | ||
58 | size[ImageDimension-1] = 0; | |
59 | ||
60 | region.SetSize(size); | |
61 | ||
62 | ImageType::Pointer scaledImage; | |
63 | scaledImage = image; | |
64 | ||
65 | for(int i=0; i < nrofloops; i++) | |
66 | { | |
67 | volumestart[ImageDimension-1] = i; | |
68 | region.SetIndex(volumestart); | |
69 | scaledImage = randomscaler(scaledImage, region); | |
70 | } | |
71 | ||
72 | return 0; | |
73 | } |