[Insight-users] itk/vtk rgb/luminance translation confusion

Rishi Graham rishig at soe.ucsc.edu
Tue Sep 17 22:13:27 EDT 2013


Hi Matt,

Thank you for looking at this.  I did see that I can do it inline, but it really seemed less than optimal to have to repeat all that code at the top level.  After playing with it a bit, it is clear that the problem lies in the setupForVTK function (I created a simpler test case which only calls setupForVTK on both files and it still has the same issue).  I'm still not entirely sure what I was doing wrong.  I tried creating the vtkSmartPointer in main and passing it in, but it did not help.  

Anyway, I did find that I can work around this by using ImageToVTKImageFilter  into vtkImageFlip instead of FlipImageFilter into ImageToVTKImageFilter (code follows).

Thanks again for your help!
-Rishi.

vtkSmartPointer<vtkImageData> setupVTKthenFlip(tmfIOImageType::Pointer imageIn){
    typedef itk::ImageToVTKImageFilter<tmfIOImageType>  ConnectorType;
    typedef vtkSmartPointer<vtkImageFlip> flipType;
    vtkSmartPointer<vtkImageData> connectorOutput;

    ConnectorType::Pointer connector = ConnectorType::New();
    connector->SetInput(imageIn);
    connector->Update();
    connectorOutput = connector->GetOutput();
    
    flipType flipFilter = flipType::New();
    flipFilter->SetFilteredAxis(1); // flip y axis
    flipFilter->SetInputDataObject(0,connectorOutput);
    flipFilter->Update();
    return(flipFilter->GetOutput());
}


On Sep 17, 2013, at 4:12 PM, Matt McCormick <matt.mccormick at kitware.com> wrote:

> Hi Rishi,
> 
> I believe there is an error in how the vtkSmartPointer's are being
> passed around the functions.  If the code is moved out of the
> functions to inline, it appears to work correctly.
> 
> HTH,
> Matt
> 
> On Wed, Sep 4, 2013 at 10:15 PM, Rishi Graham <rishig at soe.ucsc.edu> wrote:
>> Hello,
>> 
>> I am a complete itk/vtk noob.  Please excuse the vague title, I am
>> absolutely baffled as to exactly where my code is going wrong.  For this
>> reason, I am also unsure how to search the insight-users archive for similar
>> issues (although I have tried).  I admit, it's been a while since I was
>> regularly coding in c++, so there is probably a very simple mistake
>> somewhere.  I am trying to do something I think is fairly simple and getting
>> results I was not expecting.  The code, input, and output screenshots are
>> attached.  I'm running this on a Mac (OS 10.8.4), with ITK version 4.4.1,
>> VTK6.0.0.  Here is a rundown of what I'm trying to do and what's unexpected.
>> 
>> The goal is to produce a vtkRenderWindow with 2 images as follows.
>> Image1:
>> 1) loaded from jpeg as an rgb image
>> 2) run through ImageToVTKImageFilter (with a flip filter to get the
>> orientation right)
>> 3) rendered and displayed (as the "raw" input data)
>> 
>> Image2:
>> 1) loaded from jpeg as an rgb image
>> 2) run through an RGBToLuminanceFilter
>> 3) cast back into RGB with CastImageFilter
>> 4) run through  ImageToVTKImageFilter (with a flip filter to get the
>> orientation right)
>> 5) rendered and displayed (as the "processed" output data)
>> 
>> I expect that Image1 will look like the original jpg, while Image2 will just
>> be a greyscale version of the original.  This happens as expected when the
>> input files contain different pictures (attached "GoodOutput.png").
>> However, if I load the same jpg file in step 1 for both images, then what I
>> see is the expected (greyscale) output in the Image2 slot, and a flipped
>> version of the greyscale image in the Image1 slot ("BadOutput.png").  This
>> same result holds if I duplicate the file and pass in the two different (but
>> identical) input files.  Any idea where I have gone wrong?
>> 
>> I set this up as a simple test case, my ultimate goal is to extract an ROI
>> from an RGB image, processing it as grayscale, then placing the result back
>> into the original (color) image.  If there is a better way to go about this,
>> I'd love to know!
>> 
>> Thank you for your time,
>> -Rishi.
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> _____________________________________
>> 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
>> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130917/3aa6bb46/attachment.htm>


More information about the Insight-users mailing list