[Insight-users] container for iterators of images
Hila Hiler
hilahiler at gmail.com
Mon Apr 23 15:12:06 EDT 2012
Dear all responders,
Many thanks for the warm replies.
I learned a lot from your ideas.
Robert, your implementation is very helpful and really answered my needs
because less iterators increments are needed :-)
eventually, I managed with the implementation but just wanted to notify
that with the following code due to most of your suggestions:
for (it = list.begin(); it < list.end(); it++)
{
output_val =(*it)->Get() + output_val; //get values from each
image and insert in the output image
++(*it);
}
I encountered with a run time error:
Unhandled exception ...: Access violation reading location ...
const IndexType &bufferedRegionIndex =
this->GetBufferedRegion().GetIndex();
ImageHelper<VImageDimension,VImageDimension>::ComputeIndex(bufferedRegionIndex,
offset, m_OffsetTable, index);
after debugging it has turned out that this RT error occurred before the
end of the image line.
(for example: my x dimension is x1=a and that RT occurs at x1=a-1).
What have I missed?
Best,
Hila
On Mon, Apr 23, 2012 at 6:13 PM, robert tamburo <robert.tamburo at gmail.com>wrote:
> Assuming the images have corresponding pixels by the same index, another
> approach is to use an iterator to parse the output image, then get the
> value of the pixel for each image in a list and compute the output value.
> Non-compilable code:
>
> // Iterate over the output image with ImageRegionIteratorWithIndex (e.g.,
> output_it)
> for(output_it.GoToBegin(); !output_it.IsAtEnd(); ++output_it)
> {
> // Get the index during image iteration
> index = it.GetIndex();
> // Iterate over a list of images
> for(unsigned int i = 0 ; i < imageList.size(); i++)
> {
> output_val += imageList[i]->GetPixel(index);
> }
> // Set pixel in output image to output_val.
> output_image->SetPixel(index);
>
> // Reset output_val
> output_val = 0;
> }
>
> ----> That being said, take a look at itkNaryAddImageFilter. I think that
> does what you want.
>
>
>
> On Mon, Apr 23, 2012 at 10:40 AM, Hila Hiler <hilahiler at gmail.com> wrote:
>
>> Thank you for your interest.
>>
>> I'll try to explain it as clear as I can...
>> The major goal is to generate an image which any of its pixel is the sum
>> of other images corresponding pixels.
>> For example: any pixel of the new image should be the sum of the
>> corresponding pixels from the other images (im1(pix) = im2(pix)+im3(pix)).
>> Note that because I don't know in advance the number of the input images,
>> I created a STL container to store the iterators of the images. I chose
>> this way in because later I can increment all the iterators in one loop
>> (until the end of the container) ...
>>
>> So, back to my code:
>>
>> vector of iterators:
>> | it_1 | it_2 | ... | it_n |
>>
>> // iterators for the n input images
>> constIteratorType it_1 (img_1, img_1->GetRequestedRegion());
>> constIteratorType it_2 (img_2, img_2->GetRequestedRegion());
>> ...
>> constIteratorType it_n (img_n, img_n->GetRequestedRegion());
>>
>> //iterator of the output image
>> iteratorType output_it (output_img, output_img->
>> GetRequestedRegion());
>>
>> //container to store the iterators
>> std::list<constIteratorType> list;
>> std::list<constIteratorType>::iterator it;
>>
>> // iterator of the list that suppose to initialize all of the iterators
>> (it_1, it_2, etc)
>> for(it = list.begin(); it < list.end(); it++)
>> {
>> it->GoToBegin();
>> }
>>
>> //move in parallel with all of the input images and set in the output
>> image the sum of the corresponding images pixel
>> for(output_it.GoToBegin(); !output_it.IsAtEnd(); ++output_it)
>> {
>> output_val = 0;
>> for (it = list.begin(); it < list.end(); it++) //move on each
>> image in the list and get it's pixel value
>> {
>> output_val = it->Get() + output_val; //get values from each
>> image and insert in the output image
>> // How do I forward the image's iterator from here ?????
>> }
>> output_it.Set(output_val);
>> }
>>
>> Hope that now it's clearer ...
>>
>> Hila
>>
>>
>>
>> On Mon, Apr 23, 2012 at 4:51 PM, alex Dowson <alexdowson at hotmail.com>wrote:
>>
>>> Hi
>>>
>>> I think I still did not understand your problem completely . Why you
>>> want to store image in container ? Can you describe what exactly you
>>> trying to do ?
>>>
>>>
>>> Alex
>>>
>>>
>>> *From:* Hila Hiler <hilahiler at gmail.com>
>>> *Sent:* Monday, April 23, 2012 7:15 PM
>>> *To:* alex Dowson <alexdowson at hotmail.com>
>>> *Cc:* insight-users at itk.org
>>> *Subject:* Re: [Insight-users] container for iterators of images
>>>
>>> Hi Alex,
>>> first of all, many thanks for the response.
>>>
>>> I'm afraid that you haven't noticed that I did the same as described in
>>> your link (it was the easy part) ...
>>> Actually my question was about a vector of iterators to itk images.
>>> Please, read my attached code. I'll be pleased to understand what have I
>>> missed.
>>>
>>> Regards,
>>> Hila
>>>
>>>
>>> On Mon, Apr 23, 2012 at 4:08 PM, alex Dowson <alexdowson at hotmail.com>wrote:
>>>
>>>> Hi
>>>>
>>>> Look at this examples
>>>>
>>>>
>>>> http://www.itk.org/Wiki/ITK/Examples/Iterators/ImageRegionConstIterator
>>>> http://www.itk.org/Wiki/ITK/Examples/Iterators/ImageRegionIterator
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> *From:* Hila Hiler <hilahiler at gmail.com>
>>>> *Sent:* Monday, April 23, 2012 5:57 PM
>>>> *To:* insight-users at itk.org
>>>> *Subject:* [Insight-users] container for iterators of images
>>>>
>>>> Hi All,
>>>>
>>>> I'd like to generate a new image by summarizing some other images in
>>>> the same dimensions.
>>>> So I generated a new image and a std::list for the images iterators.
>>>> (actually, I thought that this dynamic container is the best way to mange
>>>> an unknown number of images)
>>>>
>>>> For now, it isn't working because I don't know how to forward the
>>>> image's iterator from that vector. in other words, how do I do the same as:
>>>> output_it++ from a vector?
>>>>
>>>> Here is my code:
>>>>
>>>> typedef itk::ImageRegionIterator <ImageType>
>>>> iteratorType;
>>>> typedef itk::ImageRegionConstIterator <ImageType>
>>>> constIteratorType;
>>>>
>>>> constIteratorType first_it (first_img,
>>>> first_img->GetRequestedRegion());
>>>> iteratorType output_it (output_img, output_img->
>>>> GetRequestedRegion());
>>>>
>>>> std::list<constIteratorType> list;
>>>> std::list<constIteratorType>::iterator it;
>>>>
>>>> list.push_back(first_it);
>>>>
>>>> if (second_img.IsNotNull())
>>>> {
>>>> constIteratorType second_it (second_img,
>>>> second_img->GetRequestedRegion());
>>>> list.push_back (second_it);
>>>> }
>>>>
>>>> //initialize all the iterators at the begin of input images
>>>> for(it = list.begin(); it < list.end(); it++)
>>>> {
>>>> it->GoToBegin();
>>>> }
>>>>
>>>> for(output_it.GoToBegin(); !output_it.IsAtEnd(); ++output_it)
>>>> {
>>>> for(it = list.begin(); it < list.end(); it++)//move on the
>>>> images and get at each iteration the pixel value and insert to the new image
>>>> {
>>>> output_val = it->Get() + output_val; //get values from
>>>> each image and insert in the output image
>>>> // How do I forward the image's iterator from here ?????
>>>> }
>>>>
>>>> output_it.Set(output_val);
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> Any thoughts would be very welcome ...
>>>> Hila
>>>> ------------------------------
>>>> _____________________________________
>>>> Powered by www.kitware.com
>>>>
>>>> Visit other Kitware open-source projects at
>>>> http://www.kitware.com/opensource/opensource.html
>>>>
>>>> Kitware offers ITK Training Courses, for more information visit:
>>>> http://www.kitware.com/products/protraining.php
>>>>
>>>> Please keep messages on-topic and check the ITK FAQ at:
>>>> http://www.itk.org/Wiki/ITK_FAQ
>>>>
>>>> Follow this link to subscribe/unsubscribe:
>>>> http://www.itk.org/mailman/listinfo/insight-users
>>>>
>>>
>>>
>>
>>
>> _____________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Kitware offers ITK Training Courses, for more information visit:
>> http://www.kitware.com/products/protraining.php
>>
>> Please keep messages on-topic and check the ITK FAQ at:
>> http://www.itk.org/Wiki/ITK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.itk.org/mailman/listinfo/insight-users
>>
>>
>
>
> --
> robert
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120423/5678ba75/attachment.htm>
More information about the Insight-users
mailing list