[Insight-users] Labeling an image and displaying results with distinguished levels of gray/colors
Malsoaz James
jmalsoaz at yahoo.fr
Thu Dec 3 05:36:38 EST 2009
Hello, I'm trying to label a binary image. For that, I have been using ConnectedComponentImageFilter and RelabelComponentImageFilter with no problem apparently.
I'm able to get the number of objects and the size of them. But I can't figure out how to display the objects found in the image with different levels of gray (prefered solution) or different colors. Indeed, I'm getting an almost black image where I can difficultly distinguish the objects.
I would really appreciate some help to solve this.
Thank you.
James
By the way, here is my code:
typedef unsigned char PixelType;
typedef itk::Image<PixelType, 2> ImageType;
typedef itk::ImageFileReader<ImageType> ReaderType;
typedef itk::ImageFileWriter<ImageType> WriterType;
typedef itk::ConnectedComponentImageFilter <ImageType, ImageType> LabelType;
typedef itk::RelabelComponentImageFilter <ImageType, ImageType> RelabelType;
int main(int argc, char *argv[])
{
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
LabelType::Pointer labeler = LabelType::New();
RelabelType::Pointer relabeler = RelabelType::New();
reader->SetFileName("input.bmp");
labeler->SetInput(reader->GetOutput());
labeler->Update();
relabeler->SetInput(labeler->GetOutput());
relabeler->Update();
for (unsigned int i=0; i<relabeler->GetNumberOfObjects(); i++)
{
std::cout<<"Number of pixel for object "<<i<<": "<<relabeler->GetSizeOfObjectsInPixels()[i]<<std::endl;
}
writer->SetFileName("output.bmp");
writer->SetInput(relabeler->GetOutput());
writer->Update();
return EXIT_SUCCESS;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091203/216e0ade/attachment.htm>
More information about the Insight-users
mailing list