[Insight-users] Filtering region by region an image

Mathieu Malaterre Mathieu.Malaterre@creatis.insa-lyon.fr
Fri, 21 Feb 2003 16:23:14 +0100


THANK YOU JAMES ! (cry of joy)

Right, I tried your suggested pipeline, and it seems to work. If I print
someFilter->GetOutput()->Print(cout);

I got:
Image (0x8082100)
   Reference Count: 2
   Modified Time: 60
   Debug: Off
   Observers:
     none
   Source: (0x80818d0)
   Source output index: 0
   Release Data: Off
   Data Released: False
   Global Release Data: Off
   PipelineMTime: 52
   UpdateTime: 62
   LastRequestedRegionWasOutsideOfTheBufferedRegion: 1
   LargestPossibleRegion:
     Dimension: 2
     Index: [0, 0]
     Size: [1402, 424]
   BufferedRegion:
     Dimension: 2
     Index: [50, 50]
     Size: [50, 50]
   RequestedRegion:
     Dimension: 2
     Index: [50, 50]
     Size: [50, 50]
   Origin: [0, 0]
   Spacing: [1, 1]
   PixelContainer: ImportImageContainer (0x80821b8)
   Reference Count: 2
   Modified Time: 61
   Debug: Off
   Observers:
     none
   Pointer: 0x80821e4
   Container manages memory: true
   Size: 2500
   Capacity: 2500


when I try to write it back to a file I got a seg fault, because the 
output image is smaller than the original image. By the way I don't 
understand why this happen because

LargestPossibleRegion: Size: [1402, 424] (which is the initial image).

But anyway, I guess now I'll have to play with 
ChangeInformationImageFilter to simulate your PasteImageFilter.

Again thank you,
mathieu



Miller, James V (Research) wrote:
> Mathieu,
> 
> Seeing you last post, it is clear that I misunderstood your question.
> 
> Given your picture below:
> 
> 
>>A is the image I read from file (FileReader) but I want to process 
>>*only* the subregion B of this image and then write back an image of 
>>same dimension as A but with the subregion B filtered.
> 
> 
> 
> -----------------------------------
> | A                               |
> |                                 |
> |   --------                      |
> |   |  B   |         --------     |
> |   --------         |   E  |     |
> |       --------     --------     |
> |       |  C   | --------         |
> |       -------- |  D   |         |
> |                --------         |
> |                                 |
> -----------------------------------
> 
> You can have your filter just process the region B via the methods
> you have been looking
> 
> someFilter->SetInput( someReader->GetOutput() );
> someFilter->GetOutput()->SetRequestedRegion( bRegion );
> someFilter->Update();
> 
> This will tell "someFilter" to just process the region of the input
> image labelled B.  The output of someFilter will be just the processed
> region. You could also extract the initial region using the ExtractImageFilter
> but that would copy the data an extra time.
> 
> This is almost what you want.  What is missing is an ability to 
> paste this result back into image A.  Someone here was supposed to 
> write a filter to do this but apparently it did not get into
> the toolkit.  I'll check around.
> 
> If it did exist (and it was called itk::PasteImageFilter), then your
> pipeline could look like
> 
> someFilter->SetInput( someReader->GetOutput() );
> someFilter->GetOutput()->SetRequestedRegion( bRegion );
> someFilter->Update();
> 
> pasteFilter->SetInput1( someReader->GetOutput() );
> pasteFilter->SetInput2( someFilter->GetOutput() );
> pasteFilter->Update();
> 
> You would then grab the output of the pasteFilter to show in your gui.
> There might have to be some additional API to handle the case where
> someone wants to paste a small image into a bigger image and specify
> "where" the small image should go.
> 
> I'll put the PasteImageFilter on my list of things to do.
> 
> Jim
> 
> 
> 
> 
> 
> 
> 
> 
>>-----Original Message-----
>>From: Mathieu Malaterre 
>>[mailto:Mathieu.Malaterre@creatis.insa-lyon.fr]
>>Sent: Friday, February 21, 2003 8:34 AM
>>To: Miller, James V (Research)
>>Subject: Re: [Insight-users] Filtering region by region an image
>>
>>
>>James,
>>    I am answering off list. As I wrote in:
>>
>>http://www.itk.org/pipermail/insight-users/2003-February/002614.html
>>
>>Your solution to use StreamingImageFilter is a bit confusing. 
>>I am not 
>>trying to work on a image to big to be loaded in memory. I am 
>>trying to 
>>filter *some* regions of my initial image.
>>
>>I though it should be an easy job due to ITK design. I don't 
>>understand 
>>why I can't give an ImageRegion to the filter and work by reference 
>>instead of copy.
>>
>>Anyway thank you for your answer...it seems that ITK user 
>>group is ready 
>>to work without Luis's answers.
>>
>>mathieu
>>
>>Miller, James V (Research) wrote:
>>
>>>If you put a StreamingImageFilter at the end of your 
>>
>>pipeline, and set
>>
>>>the number of divisions to 4, then the StreamingImageFilter 
>>
>>will execute
>>
>>>the upstream pipeline 4 times each with a different RequestedRegion 
>>>and tile the results into a single image.  Unfortunately, the 
>>>default ImageRegionSplitter used by the 
>>
>>StreamingImageFilter will divide
>>
>>>your input image like
>>>
>>>  ---------------------------
>>> |            1              |
>>> |---------------------------|
>>> |            2              |
>>> |---------------------------|
>>> |            3              |
>>> |---------------------------|
>>> |            4              |
>>>  ---------------------------
>>>
>>>But if you set the RegionSplitter (via the 
>>
>>SetRegionSplitter() method on the StreamingImageFilter) to
>>
>>>a itk::ImageRegionMultipleDimensionSplitter you can control 
>>
>>the splits to be 
>>
>>>  ---------- ----------
>>>  |         |         |
>>>  |         |         |
>>>  |    1    |     2   |
>>>  |         |         |
>>>  ---------- ----------
>>>  |         |         |
>>>  |         |         |
>>>  |    3    |     4   |
>>>  |         |         |
>>>  ---------------------
>>>
>>>I haven't tried this in a while so let me know if you have 
>>
>>any problems.  Also, using the
>>
>>>StreamingImageFilter assumes that the upstream pipeline 
>>
>>support streaming. 
>>
>>>
>>>
>>>
>>>
>>>>-----Original Message-----
>>>>From: Mathieu Malaterre 
>>>>[mailto:Mathieu.Malaterre@creatis.insa-lyon.fr]
>>>>Sent: Thursday, February 20, 2003 10:33 AM
>>>>To: ITK Users
>>>>Subject: [Insight-users] Filtering region by region an image
>>>>
>>>>
>>>>Hi all,
>>>>
>>>>  I would like to know, how I can work on a region of an 
>>>>image. I tried 
>>>>to do it with ExtractImageFilter but I fail to make it work.
>>>>
>>>>  The output of the filter where of the size of the 
>>
>>extracted region 
>>
>>>>(which is the way ExtractImageFilter is supposed to work: decrease 
>>>>size), but I wanted it to be of size of the initial image 
>>
>>(= input of 
>>
>>>>ExtractImageFilter)
>>>>
>>>>  Basically here is what I want to do. Let say I have an 
>>>>image that I 
>>>>want to filter on 4 distinct parts (not necesseraly identical).
>>>>
>>>>---------- ----------
>>>>|         |         |
>>>>|         |         |
>>>>|    1    |     2   |
>>>>|         |         |
>>>>---------- ----------
>>>>|         |         |
>>>>|         |         |
>>>>|    3    |     4   |
>>>>|         |         |
>>>>---------------------
>>>>
>>>>  Could someone give me the pipeline to use ? So that at the 
>>>>end I have 
>>>>filtered the whole image (I don't know how to concat images 
>>>>after having 
>>>>them extracted through ExtractImageFilter).
>>>>
>>>>  Should I use ImageRegion/ ImageRegionIterator/ 
>>
>>ExtractImageFilter ?
>>
>>>>  Hoping to be clear,
>>>>
>>>>  Thank you,
>>>>  Mathieu Malaterre
>>>>
>>>>
>>>>-- 
>>>>Mathieu Malaterre
>>>>CREATIS
>>>>28 Avenue du Doyen LEPINE
>>>>B.P. Lyon-Montchat
>>>>69394 Lyon Cedex 03
>>>>http://www.creatis.insa-lyon.fr/~malaterre/
>>>>
>>>>_______________________________________________
>>>>Insight-users mailing list
>>>>Insight-users@public.kitware.com
>>>>http://public.kitware.com/mailman/listinfo/insight-users
>>>>
>>>
>>>
>>
>>-- 
>>Mathieu Malaterre
>>CREATIS
>>28 Avenue du Doyen LEPINE
>>B.P. Lyon-Montchat
>>69394 Lyon Cedex 03
>>http://www.creatis.insa-lyon.fr/~malaterre/
>>
> 
> 


-- 
Mathieu Malaterre
CREATIS
28 Avenue du Doyen LEPINE
B.P. Lyon-Montchat
69394 Lyon Cedex 03
http://www.creatis.insa-lyon.fr/~malaterre/