Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
37 Views

ResizeSqrPixel

Jump to solution
Hi all again, i'm trying to resize an image by certain zoom factor. The problem is that, depending on zoom factor, i get different x value shifting.
To make you understand:

original image is 2560 x 3074

zoom factor of 2 i get the right image (see bottom for example)
zoom factor of 3 i get the pixel shifted by ~0.x * image line position (see bottom for example)
zoom 4 ok
zoom 5 ok
zoom factor of 6 i get the pixel shifted by ~0.x * image line position
etc....

i think it can be some "Rounding problem" but i can't pointing it out. Can someone help me?

Thanks in advance, Andreoli Carlo

code snippet:
[cpp]img_final_w=(int)System::Math::Floor((double)(img_original_w/zoom_value));
img_final_h=(int)System::Math::Floor((double)(img_original_h/zoom_value));


pin_ptrtmpP1 = &this->img_data_btx[0]; //don't watch these
unsigned char *np1 = tmpP1; //don't watch these
pin_ptrtmpP2 = &this->img_data_btx_z[0]; //don't watch these
unsigned char *np2 = tmpP2; //don't watch these

IppiRect srcRoi;
srcRoi.x=0;
srcRoi.y=0;
srcRoi.width = img_original_w;
srcRoi.height = img_original_h;
IppiSize srcRoiSz;
srcRoiSz.width = img_original_w;
srcRoiSz.height = img_original_h;

IppiRect dstRoi;
dstRoi.x=0;
dstRoi.y=0;
dstRoi.width = img_final_w;
dstRoi.height = img_final_h;

// calculation of work buffer size
int bufsize=0;
ippiResizeGetBufSize( srcRoi, dstRoi, 1, IPPI_INTER_LINEAR , &bufsize );
array ^tmp_bf=gcnew array(bufsize);
pin_ptrtmpP3 = &tmp_bf[0];
unsigned char *np3 = tmpP3;


ippiResizeSqrPixel_16u_C1R((Ipp16u *)tmpP1,
srcRoiSz,
img_original_w*2,
srcRoi,
(Ipp16u *)tmpP2,
img_final_w*2,
dstRoi,
(1/zoom_value),
(1/zoom_value),
0,
0,
IPPI_INTER_LINEAR ,
np3
);[/cpp]


example of zoom 2x
23650-2.gif

example of zoom 3x, pixel shifting
23651-3.gif
0 Kudos

Accepted Solutions
Highlighted
Employee
37 Views
Quoting - Carlo Andreoli
maybe i find a bug in ipp function that bring me thinking about ResizeSqrPixel probem, but it was a fault by ippiScale_16u8u_C1R. Tomorrow i'll start a new tread on the bug problem. Thank you for the reply.

Hi Carlo,

The problemmay bestillin step of
ippiDup_8u_C1C3R(
(Ipp8u*) (np2),
bmp->Width,
(Ipp8u*) (tmpbd->Scan0.ToPointer()),
bmp->Width*3,
roiSz
);
as the destination image of the functionis bmp format.
As Windows Bitmap format require that address of each image row should be aligned onfour bytes resulting in one padding byte at the each image row end in case of odd image width.
If Width=853, the stride of bmp image = 2560.
So the code may be
ippiDup_8u_C1C3R(
(Ipp8u*) (np2),
bmp->Width,
(Ipp8u*) (tmpbd->Scan0.ToPointer()),
tmpbd->Stride,
roiSz
);

Regards,
Ying

View solution in original post

0 Kudos
6 Replies
Highlighted
37 Views
Naturally the problem appears when the divider give non integer result:

Ex: zoom factor of 3, width goes from 2560 to 853,333333333 periodic!!!!!!! and this is i think where the problem starts!!!
0 Kudos
Highlighted
37 Views

Hi Carlo,

it seems more like a mistake with image step parameter. In your code you do assume that image is located in memory without padding bytes at the end of each image row which not always is true (depend on how you allocate memory for image buffer). For example Windows Bitmap format require that address of each image row should be aligned on two bytes resulting in one padding byte at the each image row end in case of odd image width.

Regards,
Vladimir
0 Kudos
Highlighted
37 Views

Hi Carlo,

it seems more like a mistake with image step parameter. In your code you do assume that image is located in memory without padding bytes at the end of each image row which not always is true (depend on how you allocate memory for image buffer). For example Windows Bitmap format require that address of each image row should be aligned on two bytes resulting in one padding byte at the each image row end in case of odd image width.

Regards,
Vladimir

I don't use bitmap, i'm currently using an

array ^test

that allocate memory sequentially (i have seen it in memory dump)....as a prove you can see how the image with zoom factor of 2.0 is clearly represented. i think it's something about 2560/3 = 853,333333333 periodic, maybe its a matter of the priodic.

if someone can help me i included a sample created with visual studio 2008 and ipp 6.1.2 so you can try yourself.

i'm still trying to point it out. Thank in advance for any help.

0 Kudos
Highlighted
37 Views
maybe i find a bug in ipp function that bring me thinking about ResizeSqrPixel probem, but it was a fault by ippiScale_16u8u_C1R. Tomorrow i'll start a new tread on the bug problem. Thank you for the reply.
0 Kudos
Highlighted
Employee
38 Views
Quoting - Carlo Andreoli
maybe i find a bug in ipp function that bring me thinking about ResizeSqrPixel probem, but it was a fault by ippiScale_16u8u_C1R. Tomorrow i'll start a new tread on the bug problem. Thank you for the reply.

Hi Carlo,

The problemmay bestillin step of
ippiDup_8u_C1C3R(
(Ipp8u*) (np2),
bmp->Width,
(Ipp8u*) (tmpbd->Scan0.ToPointer()),
bmp->Width*3,
roiSz
);
as the destination image of the functionis bmp format.
As Windows Bitmap format require that address of each image row should be aligned onfour bytes resulting in one padding byte at the each image row end in case of odd image width.
If Width=853, the stride of bmp image = 2560.
So the code may be
ippiDup_8u_C1C3R(
(Ipp8u*) (np2),
bmp->Width,
(Ipp8u*) (tmpbd->Scan0.ToPointer()),
tmpbd->Stride,
roiSz
);

Regards,
Ying

View solution in original post

0 Kudos
Highlighted
37 Views
Quoting - Ying H (Intel)

Hi Carlo,

The problemmay bestillin step of
ippiDup_8u_C1C3R(
(Ipp8u*) (np2),
bmp->Width,
(Ipp8u*) (tmpbd->Scan0.ToPointer()),
bmp->Width*3,
roiSz
);
as the destination image of the functionis bmp format.
As Windows Bitmap format require that address of each image row should be aligned onfour bytes resulting in one padding byte at the each image row end in case of odd image width.
If Width=853, the stride of bmp image = 2560.
So the code may be
ippiDup_8u_C1C3R(
(Ipp8u*) (np2),
bmp->Width,
(Ipp8u*) (tmpbd->Scan0.ToPointer()),
tmpbd->Stride,
roiSz
);

Regards,
Ying

You totally get it, i didn't even thinked about this.
From the start i thinked the image should be aligned by two bytes,
but the sample were distorted by 1 px, 2 px and 3 px and this lead me to other idea....

Really really thank Ying H.
0 Kudos