[ITK] [ITK-users] Feature image

vis itkhelpacc at gmail.com
Tue Sep 29 07:17:37 EDT 2015


hey Francisco,
i tried to do as u said.. i could build the code as well .. i ran it
for itkBrainSliceComplex.mha successfully... i  need this to run for 2d
.png file.... the code run for only one iteration.. then it throws an Abort
error... pls help me out...

#include "itkImage.h" //from
http://itk.org/Wiki/ITK/Examples/Statistics/TextureFeatures
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include <itkDenseFrequencyContainer2.h>
#include "itkHistogramToTextureFeaturesFilter.h"
#include "itkScalarImageToCooccurrenceMatrixFilter.h"
#include "itkVectorContainer.h"
#include "itkAddImageFilter.h"
#include "itkMultiplyImageFilter.h"
#include "itkRegionOfInterestImageFilter.h"

//definitions of used types
typedef itk::Image<float, 2> InternalImageType; //change from 3
typedef itk::Image<unsigned char, 2> VisualizingImageType; //change to 3
typedef itk::Neighborhood<float, 2> NeighborhoodType; //change to 3
typedef
itk::Statistics::ScalarImageToCooccurrenceMatrixFilter<InternalImageType>
    Image2CoOccuranceType;
typedef Image2CoOccuranceType::HistogramType HistogramType;
typedef itk::Statistics::HistogramToTextureFeaturesFilter<HistogramType>
Hist2FeaturesType;
typedef InternalImageType::OffsetType OffsetType;
typedef itk::AddImageFilter <InternalImageType> AddImageFilterType;
typedef itk::MultiplyImageFilter<InternalImageType> MultiplyImageFilterType;

//calculate features for one offset
void calcTextureFeatureImage (OffsetType offset,
    InternalImageType::Pointer inputImage, InternalImageType::Pointer
outInertia,
    InternalImageType::Pointer outCorrelation, InternalImageType::Pointer
outEnergy)
{
    //allocate output images
    outInertia->CopyInformation(inputImage);
    outInertia->SetRegions(inputImage->GetLargestPossibleRegion());
    outInertia->Allocate();
    outInertia->FillBuffer(0);
    outCorrelation->CopyInformation(inputImage);
    outCorrelation->SetRegions(inputImage->GetLargestPossibleRegion());
    outCorrelation->Allocate();
    outCorrelation->FillBuffer(0);
    outEnergy->CopyInformation(inputImage);
    outEnergy->SetRegions(inputImage->GetLargestPossibleRegion());
    outEnergy->Allocate();
    outEnergy->FillBuffer(0);

    Image2CoOccuranceType::Pointer
glcmGenerator=Image2CoOccuranceType::New();
    glcmGenerator->SetOffset(offset);
    glcmGenerator->SetNumberOfBinsPerAxis(16); //reasonable number of bins
    glcmGenerator->SetPixelValueMinMax(0, 255); //for input UCHAR pixel type
    Hist2FeaturesType::Pointer featureCalc=Hist2FeaturesType::New();

    typedef
itk::RegionOfInterestImageFilter<InternalImageType,InternalImageType>
roiType;
    roiType::Pointer roi=roiType::New();
    roi->SetInput(inputImage);

    InternalImageType::RegionType window;
    InternalImageType::RegionType::SizeType size;
   // size.Fill(3); //window size=3x3x3
size.Fill(2);
    window.SetSize(size);
    InternalImageType::IndexType pi; //pixel index

    //slide window over the entire image
    for (unsigned x=1;
x<inputImage->GetLargestPossibleRegion().GetSize(0)-1; x++)
    {
        pi.SetElement(0,x);
        window.SetIndex(0,x-1);
        for (unsigned y=1;
y<inputImage->GetLargestPossibleRegion().GetSize(1)-1; y++)
        {
            pi.SetElement(1,y);
            window.SetIndex(1,y-1);
           /* for (unsigned z=1;
z<inputImage->GetLargestPossibleRegion().GetSize(2)-1; z++)
            {
                pi.SetElement(2,z);
                window.SetIndex(2,z-1);*/
                roi->SetRegionOfInterest(window);
                roi->Update();
                glcmGenerator->SetInput(roi->GetOutput());
                glcmGenerator->Update();
                featureCalc->SetInput( glcmGenerator->GetOutput() );
                featureCalc->Update();

                outInertia->SetPixel(pi,
featureCalc->GetFeature(Hist2FeaturesType::Inertia));
                outCorrelation->SetPixel(pi,
featureCalc->GetFeature(Hist2FeaturesType::Correlation));
                outEnergy->SetPixel(pi,
featureCalc->GetFeature(Hist2FeaturesType::Energy));
        //    }
        }
        std::cout<<'.';
    }
}

int main(int argc, char*argv[])
{
  if(argc < 2)
    {
    std::cerr << "Usage: " << argv[0] << " Required image.dcm" << std::endl;
    return EXIT_FAILURE;
    }

  std::string fileName = argv[1];

  typedef itk::ImageFileReader<InternalImageType> ReaderType;
  ReaderType::Pointer reader=ReaderType::New();
  reader->SetFileName(fileName);
  reader->Update();
  InternalImageType::Pointer image=reader->GetOutput();

  NeighborhoodType neighborhood;
  neighborhood.SetRadius(1);
  unsigned int centerIndex = neighborhood.GetCenterNeighborhoodIndex();
  OffsetType offset;

  typedef itk::ImageFileWriter<InternalImageType> WriterType;
  WriterType::Pointer writer=WriterType::New();

  for ( unsigned int d = 0; d < centerIndex; d++ )
  {
      offset = neighborhood.GetOffset(d);
      InternalImageType::Pointer inertia=InternalImageType::New();
      InternalImageType::Pointer correlation=InternalImageType::New();
      InternalImageType::Pointer energy=InternalImageType::New();
      calcTextureFeatureImage(offset, image, inertia, correlation, energy);

      writer->SetInput(inertia);
// snprintf(buf, 100, "Inertia%u.mha", d); // Warning: call to int
__builtin___snprintf_chk will always overflow destination buffer
      std::stringstream ssInertia;
     // ssInertia << "Inertia" << d << ".mha";
      ssInertia << "Inertia" << d << ".dcm";
 writer->SetFileName(ssInertia.str());
      writer->Update();
      writer->SetInput(correlation);
      std::stringstream ssCorrelation;
     // ssCorrelation << "Correlation" << d << ".mha";
  ssCorrelation << "Correlation" << d << ".dcm";
      writer->SetFileName(ssCorrelation.str());
      writer->Update();
      writer->SetInput(energy);
      std::stringstream ssEnergy;
 //     ssEnergy << "Energy" << d << ".mha";
  ssEnergy << "Energy" << d << ".dcm";
      writer->SetFileName(ssEnergy.str());
      writer->Update();
      std::cout<<'\n';
  }

  return EXIT_SUCCESS;
}


On Tue, Sep 29, 2015 at 11:59 AM, Francisco López-Franca [via ITK Insight
Users] <ml-node+s2283740n7587930h86 at n2.nabble.com> wrote:

> Hi,
> Use 2 as dimension for the image type, neighbour, and loop only for x and
> y axis, not z.
> I hope this helps.
> Regards.
>
> 2015-09-29 7:27 GMT+02:00 vis <[hidden email]
> <http:///user/SendEmail.jtp?type=node&node=7587930&i=0>>:
>
>> hey itk users
>> i was trying to learn itk and I came across a code in [1]. it takes an 3d
>> image as input and produces an feature image as an output.. i want to use
>> it
>> for 2d image... could anyone please tell me how?
>> regards
>> vis
>> [1] http://itk.org/Wiki/ITK/Examples/Statistics/TextureFeatures
>> <http://itk.org/Wiki/ITK/Examples/Statistics/TextureFeatures>
>>
>>
>>
>> --
>> View this message in context:
>> http://itk-insight-users.2283740.n2.nabble.com/Feature-image-tp7587928.html
>> Sent from the ITK Insight Users mailing list archive at Nabble.com.
>> _____________________________________
>> 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://public.kitware.com/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://public.kitware.com/mailman/listinfo/insight-users
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://itk-insight-users.2283740.n2.nabble.com/Feature-image-tp7587928p7587930.html
> To unsubscribe from Feature image, click here
> <http://itk-insight-users.2283740.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=7587928&code=aXRraGVscGFjY0BnbWFpbC5jb218NzU4NzkyOHwzNzEzNjYzNzk=>
> .
> NAML
> <http://itk-insight-users.2283740.n2.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://itk-insight-users.2283740.n2.nabble.com/Feature-image-tp7587928p7587940.html
Sent from the ITK Insight Users mailing list archive at Nabble.com.
_____________________________________
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://public.kitware.com/mailman/listinfo/insight-users


More information about the Community mailing list