Set sitk::Image pixels

I have a VTK volume (CBCT), and I converted into sitk::Image. Ok, Now, I want to melt down some pixels there, I mean to setup some pixels as air. For that I have wrote (pseudocode):

sitk::Image img = FromVTKVolume();
while (50 times)
{
std::vector<uint32_t> elem = {300, 240, 50}; // here is some consecutive values, I mean, for x 300, 301, 302, 303, and so on, the same for y: 240, 241, and so on
img.SetPixelAsInt16(elem, -300);
}
RenderVTKVolume(img);

The problem is that I see no changes on my volume. I mention that if I apply any SimpleITK filter to img (threshold or whatever), I see that changes well. Not on code from above. How can I setup a volume pixel as air on certain position ?

Hello @flaviu2,
I suspect the reason you are not seeing a difference is that the value of -300 is either not the relevant value or close to the surrounding values and when your high dynamic range data is displayed using a low dynamic range it is merged with the surrounding intensities.

In CT air is -1000. Unfortunately CBCT intensities are not standardized like CT. The way to check this is to see what the actual value for air is in your CBCT and use that if it is different from -300.

Also, after your while loop, why not just check that the GetPixelAs... gives you -300? If it does then the issue is with the display and not the data.

I have made that test, get img value before and after I setup -1000 value:

		std::vector<uint32_t> elem = output.at(i);
		TRACE("< before <<<<%d\n", img.GetPixelAsInt16(elem));
		img.SetPixelAsInt16(elem, -1000);
		TRACE("<< after <<<<%d\n", img.GetPixelAsInt16(elem));


< before <<<<2756
<< after <<<<-1000

< before <<<<2873
<< after <<<<-1000

< before <<<<3045
<< after <<<<-1000

< before <<<<2645
<< after <<<<-1000

< before <<<<2205
<< after <<<<-1000

< before <<<<2050
<< after <<<<-1000

< before <<<<1949
<< after <<<<-1000

< before <<<<1864
<< after <<<<-1000

But I see nothing on volume … and if I apply sitk::BinaryThreshold on img, I see change, of course.

You may need to convert img back into vtkImageData. Or maybe just call vtkImage->Modified();, assuming your FromVTKVolume() started from vtkImage.