[vtkusers] images cropping with an unwanted offset

Ryven swifteye at gmail.com
Thu Apr 29 20:58:45 EDT 2010


Hi

I'm having a strange problem when using vtkImageData to deal with cropping
bitmaps. I have bitmaps of size 1008 pixels (in width, height irrelevant)
where the first 504 pixels are considered 'left' and the second 504 pixels
'right'. The idea is to basically swap left and right, i.e. split the image
at the 504 pixel mark and then swap the two sides (note this isn't the same
as a mirror).

I've been trying this in a number of ways, using vtkImageCanvasSource2D and
vtkImageClip, whereby i just draw the first 504 pixels into the second
region and vice versa. However, no matter how i do this, the resultant image
*always* has a 20-30 pixel offset that just shouldn't exist. I'm getting the
whole extent of the original image and using 0.5 of the width to decide
where to start drawing the first 504 pixels (i.e. at the 504 mark) yet no
matter what, it doesn't draw in the right place.

I've provided some sample code using vtkImageCanvasSource2D to illustrate
the general idea (which doesn't work).

Any help would be greatly appreciated

Thanks



vtkImageCanvasSource2D *swapSides = vtkImageCanvasSource2D::New();
swapSides->SetNumberOfScalarComponents(3);
swapSides->SetScalarTypeToUnsignedChar();

int *extent = image->GetWholeExtent();

int width = extent [0];
int height = extent [1];


swapSides->SetExtent(0, (extent[0]-1), 0, (extent[1]-1), 0, 0);
swapSides->SetDrawColor(0, 0, 0);
swapSides->FillBox(0, extent[0], 0, extent[1]);

double *pixel = new double[3];
//draw the second half in the first half
int newX = 0;
for(int x = (width / 2); x < width; x++)
{
for(int y = 0; y < height; y++)
{
pixel[0] = image->GetScalarComponentAsFloat(x, y, 0, 0);
pixel[1] = image->GetScalarComponentAsFloat(x, y, 0, 1);
pixel[2] = image->GetScalarComponentAsFloat(x, y, 0, 2);
swapSides->SetDrawColor(pixel);
swapSides->DrawPoint(newX, y);
}
newX++;
}

//draw the first half in the second half
newX = (width / 2);
for(int x = 0; x < (width / 2); x++)
{
for(int y = 0; y < height; y++)
{
pixel[0] = image->GetScalarComponentAsFloat(x, y, 0, 0);
pixel[1] = image->GetScalarComponentAsFloat(x, y, 0, 1);
pixel[2] = image->GetScalarComponentAsFloat(x, y, 0, 2);
swapSides->SetDrawColor(pixel);
swapSides->DrawPoint(newX, y);
}
newX++;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100430/482f04d4/attachment.htm>


More information about the vtkusers mailing list