[Insight-users]Why does not iterator work?

Gavin Adler nadan.zhu at gmail.com
Sat Dec 8 22:30:37 EST 2007


The line
for(iter.Begin(); !iter.IsAtEnd(); iter.NextLine())

might be

for(iter.GoToBegin(); !iter.IsAtEnd(); iter.NextLine())


>
>
>  Hi to everyone,
>
> I have a little problem with iterator. After the reading anf the
> filtering of a JPEG image (called Temp.jpg), I want to access it reading
> the pixels value, but the constant iterator doesn't work (and sincerly I
> don't understand why) because it stops at the 35th pixel....
> Could you help me?
>
> Thanks!!
>
> Stefano
>
> ps: I put below the code...
>
>   * in the header file:
>
> typedef float PixelTypeF;
> typedef itk::Image<PixelTypeF, Dimension> ImageTypeF;
> typedef itk::ImageFileReader<ImageTypeC> ReaderTypeJPEG;
> typedef itk::RescaleIntensityImageFilter<ImageTypeC, ImageTypeF>
> RescalerTypeCtoF;
> typedef itk::RescaleIntensityImageFilter<ImageTypeF, ImageTypeC>
> RescalerTypeFtoC;
> typedef itk::RescaleIntensityImageFilter<ImageTypeF, ImageTypeF>
> RescalerTypeFtoF;
> typedef itk::DiscreteGaussianImageFilter<ImageTypeC, ImageTypeC >
> FilterType; typedef itk::DiscreteGaussianImageFilter<ImageTypeF,
> ImageTypeF > FilterTypeFF;
> typedef itk::ImageLinearIteratorWithIndex< ImageTypeF > IteratorType;
>          typedef itk::ImageLinearIteratorWithIndex< ImageTypeC >
> IteratorTypeC;
> typedef itk::ImageLinearConstIteratorWithIndex< ImageTypeF >
> ConstIterType;
>
>
>   * in the functions file:
>
> /*    Step 1  - Reading the image */
>   ReaderTypeJPEG::Pointer reader = ReaderTypeJPEG::New();
>   reader->SetFileName(temp);
>
>   RescalerTypeCtoF::Pointer ctof = RescalerTypeCtoF::New();
>   ctof->SetInput(reader->GetOutput());
>   ctof->SetOutputMaximum(255);
>   ctof->SetOutputMinimum(0);
>
>   /*    Step 2 - Filtering 50GLPF10 */
>   FilterTypeFF::Pointer filter1 = FilterTypeFF::New();
>   filter1->SetInput(ctof->GetOutput());
>   filter1->SetVariance(3.1);
>     /*    Step 3 and 4 - Maximums and minimum*/
>   ImageTypeF::Pointer imageF = filter1->GetOutput();
>
>   try
>   {
>       filter1->Update();
>   }
>   catch( itk::ExceptionObject & err)
>   {
>       cerr << "ExceptionObject caught !" << endl;
>       cerr << err << endl;
>       system("pause");
>       exit(1) ;
>   }
>
>  ConstIterType iter( imageF, imageF->GetLargestPossibleRegion() );
> iter.SetDirection(1);
>     for(iter.Begin(); !iter.IsAtEnd(); iter.NextLine())
>   {          j=0;
>       for(iter.GoToBeginOfLine(); !iter.IsAtEndOfLine(); ++iter)
>       {
>           v[j]=iter.Get();
>           cout << "Valore pixel: " << v[j] << endl;
>           cout << "Dati: " << iter.GetRegion() << endl;
>           cout << "Indice: " << iter.GetIndex() << "\n\n\n" << endl;
>           j++;
>       }
>   }
>
> Where is the mistake?
> Thanks again.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20071209/2341d37c/attachment.htm


More information about the Insight-users mailing list