[vtkusers] updating vtkImageAccumulate

Dan Lipsa dan.lipsa at kitware.com
Fri Jul 3 13:24:03 EDT 2015


Did you called Modified() on your image data? This is how downstream
algorithms know to recompute their results.

On Fri, Jul 3, 2015 at 4:50 AM mbcx9rb9 <richard.j.brown at live.co.uk> wrote:

> i have a vtkImageData, which I would like to be able to calculate the max,
> min, average, etc. via vtkImageAccumulate. Then I want to be able to edit
> the image data, update the image accumulate and see the new statistics.
>
> However, it seems that vtkImageAccumulate doesn't work how I hoped it
> would.
> When I change my image data, my image accumulate still returns the original
> statistics of the image data before I made the changes.
>
> If I edit my image data, am I obliged to reinitialise my image accumulate
> to
> be able to see the statistics on the edited image data?
>
> I have attached a simple example of a matrix with one voxel=100 and whose
> max is found with imageaccumulate. Then, a voxel of 200 is added,
> imageaccumulate is updated, but returns a max of 100 instead of the new
> 200.
> Finally, a new imageaccumulate is used to verify that the actually max is
> 200 as expected.
>
> Any ideas of where I'm going wrong would be greatly appreciated.
>
>
>
>     // create image data
>     vtkSmartPointer<vtkImageData> id =
> vtkSmartPointer<vtkImageData>::New();
>     id->SetSpacing(1,1,1);
>     id->SetExtent(0,99,0,99,0,99);
>     id->AllocateScalars(VTK_DOUBLE,1);
>
>     // set all values to zero
>     for (int i=id->GetExtent()[0]; i<=id->GetExtent()[1]; i++) {
>         for (int j=id->GetExtent()[2]; j<=id->GetExtent()[3]; j++) {
>             for (int k=id->GetExtent()[4]; k<=id->GetExtent()[5]; k++) {
>                 double* voxel =
> static_cast<double*>(id->GetScalarPointer(i,j,k));
>                 voxel[0] = 0;
>             }
>         }
>     }
>
>     // set one voxel value to 100
>     double* voxel = static_cast<double*>(id->GetScalarPointer(50,50,50));
>     voxel[0] = 100;
>
>     // set image accumulate
>     vtkSmartPointer<vtkImageAccumulate> ia =
> vtkSmartPointer<vtkImageAccumulate>::New();
>     ia->SetInputData(id);
>     ia->SetComponentExtent(id->GetExtent());
>     ia->SetComponentOrigin(id->GetOrigin());
>     ia->SetComponentSpacing(id->GetSpacing());
>     ia->Update();
>
>     // output the max in the matrix (should be 100)
>     std::cout << "max before change: " << ia->GetMax()[0] << std::endl;
>
>     // change a different voxel to 200
>     voxel = static_cast<double*>(id->GetScalarPointer(50,50,60));
>     voxel[0] = 200;
>
>     // update image accumulate
>     ia->Update();
>     std::cout << "max after change (want this value to be 200): " <<
> ia->GetMax()[0] << std::endl;
>
>     // create second image accumulate to verify that the max is, as it
> should be, 200
>     vtkSmartPointer<vtkImageAccumulate> ia2 =
> vtkSmartPointer<vtkImageAccumulate>::New();
>     ia2->SetInputData(id);
>     ia2->SetComponentExtent(id->GetExtent());
>     ia2->SetComponentOrigin(id->GetOrigin());
>     ia2->SetComponentSpacing(id->GetSpacing());
>     ia2->Update();
>     std::cout << "max with ia2 (should be 200): " << ia2->GetMax()[0] <<
> std::endl;
>
>
>
> --
> View this message in context:
> http://vtk.1045678.n5.nabble.com/updating-vtkImageAccumulate-tp5732697.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150703/015b8e42/attachment.html>


More information about the vtkusers mailing list