[Insight-users] to label continuous parts

Ivan Macia imacia at vicomtech.es
Thu, 15 Apr 2004 11:25:26 +0200


This is a multi-part message in MIME format.

------=_NextPart_000_0021_01C422DC.5A67D440
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 8bit



-----Mensaje original-----
De: Ivan Macia [mailto:imacia at vicomtech.es]
Enviado el: jueves, 15 de abril de 2004 11:08
Para: 'David Llanos'
CC: Insight Users (E-mail)
Asunto: RE: [Insight-users] to label continuous parts


Hi David,

Im attaching you a little example on how to use the filters together with a
binary image with several shapes. The example writes the result after
labelling and rellabeling using itkConnectedComponentImageFilter and
itkRelabelComponentImageFilter. As you see is very straightforward. The
labeller works find but the relabeller seems to do nothing here, I dont know
why. Maybe some1 can shed light on this.

Regards

Iván



> -----Mensaje original-----
> De: David Llanos [mailto:gva02 at elai.upm.es]
> Enviado el: miércoles, 14 de abril de 2004 19:52
> Para: Ivan Macia
> Asunto: Re: [Insight-users] to label continuous parts
>
>
> Hi Ivan
>
> I want to label a binary image only, what algorithm
> recommends me to use?
> can you put on a simple example?
>
> Thanks for all and regards,
>
> David
>
> ----- Original Message -----
> From: "Ivan Macia" <imacia at vicomtech.es>
> To: "'David Llanos'" <gva02 at elai.upm.es>
> Cc: "Insight Users (E-mail)" <insight-users at itk.org>
> Sent: Wednesday, April 14, 2004 10:15 AM
> Subject: RE: [Insight-users] to label continuous parts
>
>
> > Hi David,
> >
> > If what you have is a binary image where you have to
> distinguish several
> > connected objects itkConnectedComponentImageFilter seems
> the right filter
> to
> > use. I didn't try it myself but it seems straightforward
> but you won't
> have
> > consecutive numbers for the labels. itkRelabelComponentImageFilter
> > transforms these label numbers in continuous labels. I
> don't know if with
> > "gray" you are referring to a binary or grayscale image
> here. In the first
> > case, someone correct me if im wrong, I don't think you
> will find anything
> > easier to use. You just have to allocate memory for the
> filter, connect it
> > to the output of another filter or an image an update.
> >
> > The Watershed filter is a well-known segmentation method in the
> literature.
> > In a few words is a segmentation filter that takes a
> grayscale image as
> > input, segments it and produces a labelled image as output,
> the number of
> > different labels you get depending on the parameters you set to the
> filter.
> >
> > Hope that helps
> >
> > Iván
> >
> > ________________________________
> >
> > Iván Macía Oliver
> > Ing. Industrial
> > Ing. en Automática y Electrónica
> > Asociación VICOMTech
> > http://www.vicomtech.es
> > Paseo Mikeletegi 57, bajo
> > 20.009 Donostia-San Sebastián
> > (Gipuzkoa) SPAIN
> > Tlfno: (00 34) 943 30 92 30
> > Fax: (00 34) 943 30 93 93
> > e-mail: imacia at vicomtech.es <mailto:imacia at vicomtech.es>
> >
> > **Member of INI-GraphicsNet**
> > http://www.inigraphics.net
> >
> > VICOMTech is an ISO 9001:2000
> > certified institute
> > ______________________________
> >
> >
> >
> >
> > -----Mensaje original-----
> > De: insight-users-admin at itk.org
> [mailto:insight-users-admin at itk.org]En
> > nombre de David Llanos
> > Enviado el: martes, 13 de abril de 2004 17:45
> > Para: insight-users at itk.org
> > Asunto: [Insight-users] to label continuous parts
> >
> >
> > > Hi all,
> > >
> > > I have to label the different continuous parts of an gray
> image, for
> later
> > to be able to process them and to differentiate them for blocks.
> > >
> > > I am studying the class "watershed",
> itkRelabelComponentImageFilter and
> > itkConnectedComponentImageFilter of ITK, but I think that the code
> examples
> > are too intricate for what I look for. I need only a simple labeled.
> > >
> > > would you be able to help me with an example but simple
> or concise?
> > >
> > > Thanks in advange and regards,
> > >
> > > David.
> >
> >
>
>

------=_NextPart_000_0021_01C422DC.5A67D440
Content-Type: text/plain;
	name="ShapeLabelling.cxx"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="ShapeLabelling.cxx"

// ShapeLabelling.cxx
// Author : Iv=E1n Mac=EDa
// 04/15/2004
// VICOMTech, Visual Communications Technologies Centre
// Paseo Mikeletegi 57, San Sebasti=E1n, Gipuzkoa, Spain

#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkMetaImageIO.h"
#include "itkImage.h"
#include "itkConnectedComponentImageFilter.h"
#include "itkRelabelComponentImageFilter.h"


int main ( int argc, char** argv )
{
=09
	// Pixel types
	typedef unsigned char			PixelType;
=09
	// Dimension
	const	unsigned int				dimension =3D 2;
=09
	// Image type
	typedef itk::Image<PixelType,dimension>  ImageType;

	// IO objects
	typedef itk::ImageFileReader<ImageType>			itkReaderType;
	typedef itk::ImageFileWriter<ImageType>			itkWriterType;
	typedef itk::MetaImageIO										itkMetaImageIOType;

	// Filters
	typedef itk::ConnectedComponentImageFilter<ImageType,ImageType>	=09
		itkConnectedComponentFilterType;
	typedef itk::RelabelComponentImageFilter<ImageType,ImageType>	=09
		itkRelabelComponentFilterType;

	// Read the meta file
	itkReaderType::Pointer			reader			 =3D itkReaderType::New();
	itkMetaImageIOType::Pointer	metaReaderIO =3D itkMetaImageIOType::New();
	reader->SetFileName( "Shapes.mhd" );
	reader->SetImageIO( metaReaderIO );
	reader->Update();

	// Labeller
	itkConnectedComponentFilterType::Pointer labeller =3D=20
		itkConnectedComponentFilterType::New();
	labeller->SetInput( reader->GetOutput() );
	labeller->Update();

	// Write labeller output
	itkWriterType::Pointer				labellerWriter				=3D itkWriterType::New();
	itkMetaImageIOType::Pointer		labellerMetaWriterIO  =3D =
itkMetaImageIOType::New();
	labellerWriter->SetInput( labeller->GetOutput() );
	labellerWriter->SetFileName( "Shapes_labelled.mhd" );
	labellerWriter->SetImageIO( labellerMetaWriterIO );
	labellerWriter->Write();

	// Relabeller
	itkRelabelComponentFilterType::Pointer relabeller =3D
		itkRelabelComponentFilterType::New();
	relabeller->SetInput( labeller->GetOutput() );
	relabeller->Update();

	// Display results
	unsigned long nObjects =3D relabeller->GetNumberOfObjects();
	const std::vector<unsigned long> sizeOfObjects =3D =
relabeller->GetSizeOfObjectsInPixels();
	std::cout << "Number of objects : " << nObjects << std::endl;
	std::vector<unsigned long>::const_iterator it;
	int i;
	for(i =3D 0, it =3D  sizeOfObjects.begin(); it !=3D =
sizeOfObjects.end(); ++i, ++it)=09
		std::cout << "Size of object " << i+1 << ": " << (*it) << " pixels" << =
std::endl;

	// Write relabeller output
	itkWriterType::Pointer				relabellerWriter				=3D itkWriterType::New();
	itkMetaImageIOType::Pointer		relabellerMetaWriterIO  =3D =
itkMetaImageIOType::New();
	relabellerWriter->SetInput( labeller->GetOutput() );
	relabellerWriter->SetFileName( "Shapes_relabelled.mhd" );
	relabellerWriter->SetImageIO( labellerMetaWriterIO );
	relabellerWriter->Write();

	return 0;=09

}
------=_NextPart_000_0021_01C422DC.5A67D440--