i have noticed if i use for-loop across the image to get the every pixel value is time-consuming and inefficient,and that is also be mentioned in the user guide.
I read this page https://itk.org/Doxygen50/html/ImageIteratorsPage.html
but i still dont know how to get the pixel value and get its coordinates at the same time with using iterator.
Here is my code how can i rewrite them with using iterator.
ImageType::IndexType pixcelIndex;
int image_width = RegionInFilter.GetSize()[0];
int image_height = RegionInFilter.GetSize()[1];
int image_slice = RegionInFilter.GetSize()[2];
for (int k = 0; k < image_slice; ++k) //
{
for (int i = 0; i < image_height; ++i)//
{
for (int j = 0; j < image_width; ++j)//
{
pixcelIndex[0] = j;//
pixcelIndex[1] = i;//
pixcelIndex[2] = k;//
ImageType::PixelType pixel1 = image->GetPixel(pixcelIndex);
if (pixel1 !=0 ) {
slicecoordinates .push_back(pixcelIndex[2]);//
Ycoordinates .push_back(pixcelIndex[1]);//
Xcoordinates .push_back(pixcelIndex[0]);//
}
}
}
}
now the code is running good but also use too much memory so I want to optimize it .
Thanks in advance!!
Thank you!! And i want to know how apply image filter on dicom series? All example is base on single image .Now i read a dicom series and i want to do the same processing on every slice,for example opening operation. But it didn`t work. i want to konw how to apply it in right way.
Oh sorry there is my copy mistake. Because I use a lot of filters.I pick out some of the code for the sake of simplicity.
It is indeed openingFilter->SetInput(filter->GetOutput()) in my code;
every single filter does not work except OtsuThresholdImageFilter . I have tried to apply many Morphological operation ,opening closing,Dilate… But the image hasn’t been changed.
also i have changed structuringElement.SetRadius(15); biger or smaller it does not help neither.
What’s special is that my data is a dicom series, so I think something should be changed, but I’m not sure where.
That problem is unrelated to iterators. Please start a new topic, preferably providing a minimal complete example (with just one filter) which can be copy-pasted for easy reproduction.