[Insight-users] to divide images
David Llanos
gva02@elai.upm.es
Thu May 20 15:49:39 EDT 2004
This is a multi-part message in MIME format.
------=_NextPart_000_0007_01C43E8A.70DC6F00
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Hi Zach,
I also hope we can get that this works. Once again, thank you for your
attention. Here I attach you all the files of my application, and next the
errors:
------------------------------------------------------
Compiling...
etiquetar.cxx
E:\Etiquetar\etiquetar.cxx(25) : error C2665: 'GetMasks' : none of the 2
overloads can convert parameter 1 from type 'class itk::Image<unsigned
char,2> *'
E:\Etiquetar\etiquetar.cxx(33) : error C2664: 'SetInput' : cannot convert
parameter 1 from 'const class itk::SmartPointer<class itk::Image<unsigned
char,2> >' to 'const class itk::Image<unsigned char,2> *'
No user-defined-conversion operator available that can perform this
conversion, or the operator cannot be called
Error executing cl.exe.
etiquetar.exe - 2 error(s), 0 warning(s)
------------------------------------------------------
Regards,
David.
----- Original Message -----
From: "Zachary Pincus" <zpincus@stanford.edu>
To: "David Llanos" <gva02@elai.upm.es>
Sent: Wednesday, May 19, 2004 9:26 PM
Subject: Re: [Insight-users] to divide images
> David,
>
> This is quite odd, indeed. Could you send me again the *exact* code
> you're trying to compile, along with the errors?
>
> I am very surprised that it won't compile for you. Hopefully we can get
> this working.
>
> Zach
------=_NextPart_000_0007_01C43E8A.70DC6F00
Content-Type: application/octet-stream;
name="GetConnectedMasks.h"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="GetConnectedMasks.h"
/* GetConnectedMasks.h :: Zachary Pincus 3/31/2004
* ----------------------------------------------------
*
*/
=20
#ifndef _GetConnectedMasks_h_
#define _GetConnectedMasks_h_
#include <vector>
namespace CellExplorer { namespace CellExtractor {
=09
template<class TImage> void GetMasks(typename TImage::Pointer =
maskImage,
std::vector<typename TImage::Pointer > &submasks, bool fullyConnected =
=3D false);
}} // end of namespaces
#include "GetConnectedMasks.txx"
#endif
------=_NextPart_000_0007_01C43E8A.70DC6F00
Content-Type: application/octet-stream;
name="GetConnectedMasks.txx"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="GetConnectedMasks.txx"
#ifndef _GetConnectedMasks_txx_
#define _GetConnectedMasks_txx_
#include "GetConnectedMasks.h"
#include <iostream>
#include <map>
#include "itkSmartPointer.h"
#include "itkConnectedComponentImageFilter.h"
#include "itkImageRegionIterator.h"
#include "itkImageRegionConstIterator.h"
#include "itkNumericTraits.h"
#include "itkEquivalencyTable.h"
#include "itkConstShapedNeighborhoodIterator.h"
#include "itkConstantBoundaryCondition.h"
#include "itkImageRegionConstIteratorWithIndex.h"
namespace CellExplorer { namespace CellExtractor {
template<class TImage> void GetMasks(typename TImage::Pointer maskImage,
std::vector<typename TImage::Pointer > &submasks, bool fullyConnected) =
{
=09
typedef TImage ImageType;
typedef typename ImageType::PixelType PixelType;
typedef typename ImageType::SizeType SizeType;
typedef typename ImageType::IndexType IndexType;
typedef typename ImageType::RegionType RegionType;
typedef unsigned short LabelPixelType;
typedef itk::Image<LabelPixelType, 2> LabelImageType;
=09
RegionType masterRegion =3D maskImage->GetLargestPossibleRegion();
=09
// create an image to hold component labels
=09
LabelImageType::Pointer labelImage =3D LabelImageType::New();
labelImage->SetRegions(masterRegion);
labelImage->Allocate();
labelImage->FillBuffer(itk::NumericTraits<LabelPixelType>::Zero);
=09
// create an equivalency table
itk::EquivalencyTable::Pointer eqTable =3D =
itk::EquivalencyTable::New();
LabelPixelType label, originalLabel, neighborLabel;
LabelPixelType maxLabel =3D itk::NumericTraits<LabelPixelType>::Zero;
const LabelPixelType maxPossibleLabel =3D =
itk::NumericTraits<LabelPixelType>::max();
// Set up the boundary condition to be zero padded (used on label =
image)
itk::ConstantBoundaryCondition<LabelImageType> BC;
BC.SetConstant(itk::NumericTraits<LabelPixelType>::Zero);
// Neighborhood iterator. Let's use a shaped neighborhood so we can
// restrict the access to face connected neighbors. This iterator
// will be applied to the output image
typedef itk::ConstShapedNeighborhoodIterator<LabelImageType> =
NeighborhoodIteratorType;
SizeType kernelRadius;
kernelRadius.Fill(1);
NeighborhoodIteratorType nit;
nit =3D NeighborhoodIteratorType(kernelRadius, labelImage, =
masterRegion);
nit.OverrideBoundaryCondition(&BC); // assign the boundary condition
// only activate the indices that are "previous" to the current
// pixel and face connected (exclude the center pixel from the
// neighborhood)
//
unsigned int d;
NeighborhoodIteratorType::OffsetType offset;
if (!fullyConnected){
// only activate the "previous" neighbors that are face connected
// to the current pixel. do not include the center pixel
offset.Fill(0);
for (d=3D0; d < ImageType::ImageDimension; ++d){
offset[d] =3D -1;
nit.ActivateOffset(offset);
offset[d] =3D 0;
}
} else {
// activate all "previous" neighbors that are face+edge+vertex
// connected to the current pixel. do not include the center pixel
unsigned int centerIndex =3D nit.GetCenterNeighborhoodIndex();
for (d=3D0; d < centerIndex; d++) {
offset =3D nit.GetOffset(d);
nit.ActivateOffset(offset);
}
}
// along with a neighborhood iterator on the input, use a standard
// iterator on the input and output
itk::ImageRegionConstIterator<ImageType> it;
itk::ImageRegionIterator<LabelImageType> oit;
it =3D itk::ImageRegionConstIterator<ImageType>(maskImage, =
masterRegion);
oit =3D itk::ImageRegionIterator<LabelImageType>(labelImage, =
masterRegion);
=09
// Mark the output image as either background or unlabeled
it.GoToBegin();
oit.GoToBegin();
while (!it.IsAtEnd()) {
if (it.Get() !=3D itk::NumericTraits<PixelType>::Zero) {
// mark pixel as unlabeled
oit.Set(maxPossibleLabel);
}
=09
++it;
++oit;
}
// iterate over the image, labeling the objects and defining
// equivalence classes. Use the neighborhood iterator to access the
// "previous" neighbor pixels and an output iterator to access the
// current pixel
nit.GoToBegin();
oit.GoToBegin();
while ( !oit.IsAtEnd() ) {
// Get the current pixel label
label =3D oit.Get();
originalLabel =3D label;
=09
// If the pixel is not background
if (label !=3D itk::NumericTraits<LabelPixelType>::Zero) {
// loop over the "previous" neighbors to find labels. this loop
// may establish one or more new equivalence classes
typename NeighborhoodIteratorType::ConstIterator sIt;
for (sIt =3D nit.Begin(); !sIt.IsAtEnd(); ++sIt) {
// get the label of the pixel previous to this one along a
// particular dimension (neighbors activated in neighborhood =
iterator)
neighborLabel =3D sIt.Get();
// if the previous pixel has a label, verify equivalence or
// establish a new equivalence
if (neighborLabel !=3D itk::NumericTraits<LabelPixelType>::Zero) {
// if current pixel is unlabeled, copy the label from neighbor
if (label =3D=3D maxPossibleLabel) {
// copy the label from the previous pixel
label =3D neighborLabel;
}
// else if current pixel has a label that is not already
// equivalent to the label of the previous pixel, then setup
// a new equivalence. note the use of Lookup() and not
// RecursiveLookup(). this is possible since we keep the
// equivalence table flat.
else if ((label !=3D neighborLabel)
&& (eqTable->Lookup(label) !=3D eqTable->Lookup(neighborLabel))) =
{
eqTable->Add(label, neighborLabel);
// if we keep the equivalency table up to date, then we
// can use straight calls to Lookup() instead of
// RecursiveLookUp(). This works out to be 3X faster.
eqTable->Flatten();
}
}
}
// if none of the "previous" neighbors were set, then make a new =
label
if (originalLabel =3D=3D label) {
// create a new entry label
if (maxLabel =3D=3D maxPossibleLabel) {
std::cerr << "Number of labels exceeds number of available labels =
for the output type." <<std::endl;
} else {
++maxLabel;
}
// assign the new label
label =3D maxLabel;
}
// Finally, set the output pixel to whatever label we have
if (label !=3D originalLabel)
{
oit.Set( label );
}
}
// move the iterators
++nit;
++oit;
}
// Flatten the equavalency table
eqTable->Flatten();
// remap the labels and add the indices of each labeled point to a
// vector that corresponds to each label
=09
=09
typedef std::map<LabelPixelType, std::vector<IndexType> > =
BlobTableType;
BlobTableType blobTable;
typedef itk::ImageRegionConstIteratorWithIndex<LabelImageType> =
IndexItType;
IndexItType labelIt(labelImage, masterRegion);
for(labelIt.GoToBegin(); !labelIt.IsAtEnd(); ++labelIt) {
label =3D labelIt.Get();
// if pixel has a label, write out the final equivalence
if (label !=3D itk::NumericTraits<LabelPixelType>::Zero) {
LabelPixelType flatLabel =3D eqTable->Lookup(label);
=09
// this is tricky: if gets the vector associated with a given label
// and IF the vector doesn't exist, the [] operator creates a new =
one!
blobTable[flatLabel].push_back(labelIt.GetIndex());
// Might be able to make this run faster by using an insert method =
that
// hints where in the map we insert. (always the end!)
}
}
=09
// Now, iterate through the vectors and create a small image from each
for(typename BlobTableType::iterator btIt =3D blobTable.begin();=20
btIt !=3D blobTable.end(); ++btIt) {
=09
std::vector<IndexType> indices =3D (*btIt).second;
=09
// first compute the bounding box of the indices in each vector
// (technically this step could be folded into the act of filling the =
vectors above) =09
=09
typedef typename IndexType::IndexValueType IVType;
=09
IVType xMin =3D itk::NumericTraits<IVType>::max();
IVType yMin =3D itk::NumericTraits<IVType>::max();
IVType xMax =3D itk::NumericTraits<IVType>::min();
IVType yMax =3D itk::NumericTraits<IVType>::min();
=09
for(typename std::vector<IndexType>::const_iterator idxIt =3D =
indices.begin();=20
idxIt !=3D indices.end(); ++idxIt) {
IndexType idx =3D *idxIt;
if (idx[0] < xMin) xMin =3D idx[0];
if (idx[0] > xMax) xMax =3D idx[0];
if (idx[1] < yMin) yMin =3D idx[1];
if (idx[1] > yMax) yMax =3D idx[1];
}
=09
// now create an image and put "one" values in every index listed in =
the vector
SizeType size =3D {xMax - xMin + 1, yMax - yMin + 1};
IndexType start =3D {xMin, yMin};
RegionType region;
region.SetSize(size);
region.SetIndex(start);
=09
typename ImageType::Pointer outputImage =3D ImageType::New();
outputImage->SetRegions(region);
outputImage->Allocate();
outputImage->FillBuffer(itk::NumericTraits<PixelType>::Zero);
for(typename std::vector<IndexType>::const_iterator idxIt =3D =
indices.begin();=20
idxIt !=3D indices.end(); ++idxIt) {
outputImage->SetPixel(*idxIt, itk::NumericTraits<PixelType>::One);
}
=09
// Finally, add that image to the vector that we are passed in.
submasks.push_back(outputImage);
}
}
}} // end namespaces
#endif
------=_NextPart_000_0007_01C43E8A.70DC6F00
Content-Type: image/png;
name="binar.png"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="binar.png"
iVBORw0KGgoAAAANSUhEUgAAAecAAAFsCAAAAADTES6TAAAACXBIWXMAAC4jAAAuIwF4pT92AAAE
bUl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bR+5aKmDpwFu+vup89yEBE47tHLt24LDFVo8cd8kZS2OHzXnK4i+/7pyxwy5Z
OXLcJWcsjR121bKR4y45Y2nssKuWTRx3yRlTc5ddtGzduEvO2Bs77IY164Zdcsrg2GE31Y97+0qh
5xw0K67zMqHHHDJryrI9pR5zyK4507aUeswhu+ZM21LqLUfsmrVtR6m3HLFr1rYdpZ5xSGSV36Ue
UubxEs+o8xx5Z9R5hrwzyjxF3B01nijolvc6C/1fhy5YdUmdp4m6oM4TJV1Q5xLLL6hzibd7/fxH
56d7P1v5AXXuQeceVO5B5iZEbkLnRnTuQecedO5C4DZk7kHnHnRu4j+BdX4W38OtaNyDygAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0NAP9SymMqfm
gH8AAAAASUVORK5CYII=
------=_NextPart_000_0007_01C43E8A.70DC6F00
Content-Type: application/octet-stream;
name="etiquetar.cxx"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="etiquetar.cxx"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkImage.h"
#include "itkSmartPointer.h"
#include <vector>
#include "GetConnectedMasks.h"
int main ( int argc, char * argv[] )
{
typedef unsigned char PixelType;
const unsigned int dimension =3D 2;
typedef itk::Image<PixelType,dimension> ImageType;
typedef itk::SmartPointer<ImageType::Pointer> aaa;
typedef itk::ImageFileReader<ImageType> itkReaderType;
typedef itk::ImageFileWriter<ImageType> itkWriterType;
std::vector<ImageType::Pointer> objetos;
itkReaderType::Pointer reader =3D itkReaderType::New();
reader->SetFileName( argv[1] );
reader->Update();
CellExplorer::CellExtractor::GetMasks<ImageType>(reader->GetOutput(), =
objetos, true);
std::vector<ImageType::Pointer>::const_iterator it;
int i;
for(i =3D 0, it =3D objetos.begin(); it !=3D objetos.end(); ++i, ++it) =
{
itkWriterType::Pointer submascara =3D itkWriterType::New();
submascara->SetFileName( "submascara.png" );
submascara->SetInput( *it );
submascara->Update();
}
return 0;=09
}
------=_NextPart_000_0007_01C43E8A.70DC6F00
Content-Type: text/plain;
name="CMakeLists.txt"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="CMakeLists.txt"
PROJECT(etiquetar)
FIND_PACKAGE(ITK)
IF(ITK_FOUND)
INCLUDE(${ITK_USE_FILE})
ELSE(ITK_FOUND)
MESSAGE(FATAL_ERROR
"Cannot build InsightApplications without ITK. Please set=20
ITK_DIR.")
ENDIF(ITK_FOUND)
ADD_EXECUTABLE(etiquetar etiquetar.cxx)
TARGET_LINK_LIBRARIES(etiquetar ITKCommon ITKAlgorithms ITKNumerics =
ITKBasicFilters ITKIO ITKMetaIO ITKvnl ITKNetlib ITKvnl ITKvnl_algo)
------=_NextPart_000_0007_01C43E8A.70DC6F00--
More information about the Insight-users
mailing list