Community
cancel
Showing results for 
Search instead for 
Did you mean: 
BMart1
New Contributor II
73 Views

ResizeAntialiasing does not match output of Resize* when upscaling

According to the documentation of ResizeAntialiasing, when increasing the image size it should behave as ippiResizeLinear, ippiResizeCubic, or ippiResizeLanczos. But I found a small difference:

#define _IPP_SEQUENTIAL_STATIC
#include "ippi.h"
#include "ippcc.h"
#include "ipps.h"
#include "ippcore.h"
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdint>
using namespace std;
#include "iw\include\iw++\iw.hpp"

void dump(ipp::IwiImage& img)
{
    for (int y = 0; y < img.m_size.height; ++y)
    {
        for (int x = 0; x < img.m_size.width; ++x)
        {
            cout << setw(3) << (int)(*(uint8_t*)img.ptr(x, y)) << ' ';
        }
        cout << endl;
    }
    cout << endl;
}

int main()
{
    ipp::IwiImage src;
    src.Alloc({ 4, 4 }, ipp8u, ippC1);
    ipp::IwiImage dst;
    dst.Alloc({ 12, 12 }, ipp8u, ippC1);

    for (int y = 0; y < src.m_size.height; ++y)
    {
        for (int x = 0; x < src.m_size.width; ++x)
        {
            *((uint8_t*)src.ptr(x, y)) = 10 * min(x, y);
        }
    }

    dump(src);

    for (bool antialiasing : {false, true})
    {
        int specSize = 0, initSize = 0;
        ippiResizeGetSize_8u({ src.m_size.width, src.m_size.height }, { dst.m_size.width, dst.m_size.height }, ippLinear, antialiasing, &specSize, &initSize);
        Ipp8u* pInitBuf = ippsMalloc_8u(initSize);
        //ON_BLOCK_EXIT([&] { ippsFree(pInitBuf); });
        IppiResizeSpec_32f* pSpec = (IppiResizeSpec_32f*)ippsMalloc_8u(specSize);
        //ON_BLOCK_EXIT([&] { ippsFree(pSpec); });
        if (antialiasing)
            ippiResizeAntialiasingLinearInit({ src.m_size.width, src.m_size.height }, { dst.m_size.width, dst.m_size.height }, pSpec, pInitBuf);
        else
            ippiResizeLinearInit_8u({ src.m_size.width, src.m_size.height }, { dst.m_size.width, dst.m_size.height }, pSpec);

        int bufSize = 0;
        ippiResizeGetBufferSize_8u(pSpec, { dst.m_size.width, dst.m_size.height }, 1, &bufSize);
        Ipp8u* pBuffer = ippsMalloc_8u(bufSize);
        //ON_BLOCK_EXIT([&] { ippsFree(pBuffer); });

        IppiBorderSize borderSize{};
        ippiResizeGetBorderSize_8u(pSpec, &borderSize);
        if (antialiasing)
            ippiResizeAntialiasing_8u_C1R((uint8_t*)src.ptr(), src.m_step, (uint8_t*)dst.ptr(), dst.m_step, { 0, 0 }, { dst.m_size.width, dst.m_size.height }, ippBorderRepl, nullptr, pSpec, pBuffer);
        else
            ippiResizeLinear_8u_C1R((uint8_t*)src.ptr(), src.m_step, (uint8_t*)dst.ptr(), dst.m_step, { 0, 0 }, { dst.m_size.width, dst.m_size.height }, ippBorderRepl, nullptr, pSpec, pBuffer);

        dump(dst);
    }
}

I tried 2017 U2 and 2018 beta.

Bruno

0 Kudos
2 Replies
BMart1
New Contributor II
73 Views

ResizeAntialiasing is also 3x as slow. I sometimes upscale in a dimension and downscale in the other so just calling ResizeAntialiasing/Resize* as required is no workaround.

Valentin_K_Intel
Employee
73 Views

Hi Bruno,

Thank you for the information! We will fix it for next IPP releases.

Best regards,
Valentin

Reply