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 ImageDimension = 4; | |
| 14 | typedef double PixelType; | |
| 15 | typedef itk::Image< PixelType, ImageDimension > ImageType; | |
| 16 | typedef itk::ImageFileReader< ImageType > ReaderType; | |
| 17 | typedef itk::ImageFileWriter< ImageType > WriterType; | |
| 18 | ||
| 19 | ImageType::Pointer randomscaler(ImageType::Pointer inputimage, ImageType::RegionType iterregion) | |
| 20 | {
| |
| 21 | ||
| 22 | typedef itk::MinimumMaximumImageCalculator <ImageType> ImageCalculatorFilterType; | |
| 23 | ImageCalculatorFilterType::Pointer imageCalculatorFilter = ImageCalculatorFilterType::New (); | |
| 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 | ||
| 33 | typedef itk::ImageRegionIterator< ImageType > IteratorType; | |
| 34 | IteratorType imageIterator(inputimage,iterregion); | |
| 35 | ||
| 36 | imageIterator.GoToBegin(); | |
| 37 | ||
| 38 | std::cout << "image iterator at end?" << imageIterator.IsAtEnd() << std::endl; //gives 1 always | |
| 39 | ||
| 40 | while(!imageIterator.IsAtEnd()) | |
| 41 | {
| |
| 42 | PixelType inputPixel = imageIterator.Get(); | |
| 43 | PixelType outputPixel = (inputPixel-Imin)*((Omax-Omin)/(Imax-Imin))+Omin; | |
| 44 | imageIterator.Set(outputPixel); | |
| 45 | ++imageIterator; | |
| 46 | } | |
| 47 | ||
| 48 | ImageType::Pointer outputimage = inputimage; | |
| 49 | ||
| 50 | return outputimage; | |
| 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 | std::cerr << argv[2] << " outputImageFile" << std::endl; | |
| 60 | return EXIT_FAILURE; | |
| 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 | ImageType::IndexType volumestart; | |
| 73 | volumestart = image->GetLargestPossibleRegion().GetIndex(); | |
| 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); |
| 88 | + | scaledImage = randomscaler(scaledImage, region); |
| 89 | - | scaledImage = randomscaler(scaledImage, max, region, scalingback); |
| 89 | + | |
| 90 | ||
| 91 | return 0; | |
| 92 | } |