[Insight-users] How to access a value from the index array?

David Doria daviddoria at gmail.com
Mon Oct 22 16:02:17 EDT 2012


On Mon, Oct 22, 2012 at 12:26 AM, D, Yamini <Yamini.D at philips.com> wrote:
>
> Hi,
>
>
>
> I am working on a problem which requires the access of certain values(every 5th value) from an “index” array.
>
> This is the part of the code which fetch the pointset  of the pixels which are white in the image. The pointset are stored in “index”.
>
> Outside the for loop,  I want to access every 5th value from the array index[0] (x-values) and from array[1] (y-values).
>
>
>
>
>
> //code
>
> InputImageType::IndexType index;
>
>
>
> int i,j;
>
>
>
> for (i=0;i<size_x;i++){
>
>        for (j=0;j<size_y; j++){
>
>               index[0]=i;  // x-values
>
>               index[1]=j;  // y-values
>
>
>
> InputImageType::PixelType pixelValue = image->GetPixel(index);
>
> if(pixelValue==255)
>
> cout<<index[0]<<"    " << index[1]<<endl;
>
>
>
>        }
>
> }
>
>

Are you looking to store these indices in a vector?

std::vector<InputImageType::IndexType> indices;

int i,j;

for (i=0;i<size_x;i++){

       for (j=0;j<size_y; j++){
              InputImageType::IndexType index;
              index[0]=i;  // x-values

              index[1]=j;  // y-values
              indices.push_back(index);

InputImageType::PixelType pixelValue = image->GetPixel(index);

if(pixelValue==255)

cout<<index[0]<<"    " << index[1]<<endl;
       }
}

// Here you can get every 5th element, like:
for(every 5th id)
  indices[id]

Good luck,

David


More information about the Insight-users mailing list