Menu

resize function divided on threads

c_cosmin
2016-08-10
2016-08-11
  • c_cosmin

    c_cosmin - 2016-08-10

    Hi,

    For some time I use your library.
    It is fast.
    But for very large images (1080p or bigger) one processor is not enough for realtime resizing.
    So is there a way to divide the resize of an image in 2 or more threads and getting a boost in speed as close as possible to number_of_threads_used x original_speed?

    Thank you.

    A good day.

     
  • Yermalayeu Ihar

    Yermalayeu Ihar - 2016-08-11

    Hello.

    I'm glad that the library is used by you.

    I'm surprised that performance of function ResizeBilinear is not enough to resize of Full HD image (1080p) in realtime. I have measured its performance - it is about 5-6 ms for 1920x1080x32 image (i7 4770). So there is a large reserve of performance for realtime processing even for much more weak processors (although, I could be wrong, and you may need performance for another functionality).

    Of course, it is possible to use multithreding to resize image. But implementation of the functionality might take a lot of time. Because addition of multithread processing affects for common structure of the library. So I can't promise to add multithreading in the nearest future. But I will add it to my plans.

    Sincerely, Ihar.

     
  • c_cosmin

    c_cosmin - 2016-08-11

    The computer I'm testing on has a 1.8 GHz Intel processor with 4 cores. The display has 1366x768 resolution, so I have to resize the images from 1080p..4K to that resolution and display them as fast as possible.
    It takes about 30..100 ms to resize each image, to which I add the time to generate the images (10..50 ms). So the result is a "choppy" playback.

    But I understand what you mean. Yes, implementing multithread for all functions from the library requires a lot of work.
    Your library is already one of the best SIMD library in the world even without multithreading.
    But I hope you'll also implement multithread as soon as possible...

    Thank you.

     
  • c_cosmin

    c_cosmin - 2016-08-11

    Ok, I'll try to implement the multithread in my application instead of your library by calling the resize function (from your library) for parts of the image.

    For example, an image with imgWidth and imgHeight need to be resized to imgResWidth and imgResHeight by using n threads.
    The image will be divided in n parts by dividing imgHeight to n and by adding a few rows to the begining and the end of each part (so the resize function could work with the "neighbour" pixels correctly).
    Now, the question is: from these values, how to calculate the minimum number of rows to add so the resize function would correctly resize each of the n parts?

    Can you help me with this, please?

     
  • Yermalayeu Ihar

    Yermalayeu Ihar - 2016-08-11
    float scale = (float)srcHeight/dstHeight;
    for(size_t dstIndex = 0; dstIndex < dstHeight; ++dstIndex)
    {
        float alpha = (float)((dstIndex + 0.5)*scale - 0.5);
        ptrdiff_t srcIndex = (ptrdiff_t)::floor(alpha);
        alpha -= srcIndex;
    
        if(alpha < 0.03)
        //to minimize interpolation effects at separation (smaller alpha is better)
        {
        // you can separate source (at srcIndex row)  
        // and destination (at dstIndex row) images.
        }
    } 
    

    P.S. To implement separation without any additional error this one must be implemented inside of the library.

     

    Last edit: Yermalayeu Ihar 2016-08-11
  • c_cosmin

    c_cosmin - 2016-08-11

    Thank you very much for your help.
    I will give it a try...

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.