[Insight-users] Get the value of a voxel in 3d Image

Jon Haitz Legarreta jhlegarreta at vicomtech.org
Thu Oct 24 04:57:00 EDT 2013


Dear Shiwei,
if we keep the conversation on the mailing list, you will have more chances
to have your question answered and hopefully solved.

As for the question, the pixel index type depends on the image type:

ImageType::IndexType index;

If your image is a volume, then index will be an array of dimension 3.
Thus, you'd do:

  index[0] = 0;
  index[1] = 0;
  index[2] = 0;

You should also take into account ITK's coordinate convention in order to
set the indexes properly and choose the one you want to/expect to.
Then you'd do:

ImageType::PixelType pixelValue = image->GetPixel(index)

And then you'd do your processing.

The GetLargestPossibleRegion() function will return you a RegionType type,
which is used to specify a subset region of the image. Furthermore,
GetPixel() is not a member of itk::ImageRegion, you cannot acces the pixel
through the region.

What you call Db should be a pointer to your image, like:

typedef itk::Image<YOUR_PIXEL_TYPE, YOUR_IMAGE_DIMENSION>  ImageType;

ImageType::Pointer image = ImageType::New();

That is:

ImageType::Pointer Db = ImageType::New();


HTH,
JON HAITZ



On 24 October 2013 10:33, shiwei <swingsw89 at 163.com> wrote:

> Thank you very much for help me with that! In my understanding, the code
> should be like the following?
> Index3DType pixelIndex;
> pixelIndex[0] = Point1(0,0);   // x position
> pixelIndex[1] = Point1(1,0);   // y position
> pixelIndex[2] = Point1(2,0);
> ImageType::PixelType   pixelValue = Db->GetPixel( pixelIndex );
> std::cout << Db->GetPixel(pixelIndex)<<endl;
> if(pixelValue==0)
> {
> ...
> }
>
>
> And one more question is that, shall I use " Db->GetPixel( pixelIndex )"
> or "Db->GetLargestPossibleRegion()->GetPixel( pixelIndex )" instead of
> the image?
>
>
> At 2013-10-24 14:59:48,"Jon Haitz Legarreta" <jhlegarreta at vicomtech.org>
> wrote:
>
> Hi Shiwei,
> try using
> image->GetPixel( pixelIndex );
>
> You may want to have a look at some older posts on the same issue to see
> if they are helpful:
>
> http://itk-insight-users.2283740.n2.nabble.com/Get-pixel-Data-td6035296.html
> http://www.itk.org/pipermail/insight-users/2006-January/016517.html
>
> HTH,
> JON HAITZ
>
>
> On 24 October 2013 08:08, shiwei <swingsw89 at 163.com> wrote:
>
>> Hi,all
>>        Now I run into a problem is that in a Big 3D volume named Db, I
>> want to have the following result like thie code in Matlab:
>>  *if Db( Point1(1,1) , Point1(2,1) , Point1(3,1) ) == 0 *
>> And I know Point1(1,1),Point1(2,1),Point1(3,1), I wonder if there is a
>> way in ITK to locate this coordinate and get the value of the voxel to
>> check whether it's zero? Maybe not use a SliceIterator in the whole 3d
>> volume? For before this code, I have already iterate the Db 3D volume?
>>
>>                     &nbs p;
>>                                                           Thank you
>>
>>                                                        shiwei
>>
>>
>>
>> _____________________________________
>> 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://www.itk.org/mailman/listinfo/insight-users
>>
>>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20131024/d01f6db5/attachment.htm>


More information about the Insight-users mailing list