简体   繁体   中英

how to scale gray scale image using accelerate framework (vImage)

Hi i need to scale a gray scale image fast, so i tried vImage and the app is crashing, please help. In the below code srcimg.data/dstimg.data is a point to unsigned char image data(single channel only gray data).

vImage_Buffer src;
                    src.data=srcimg.data;
                    src.height=srcimg.cols;
                    src.width=srcimg.rows;
                    src.rowBytes=srcimg.cols;

                    vImage_Buffer dest;
                    dest.data=dstimg.data;
                    dest.height=dstimg.cols;
                    dest.width=dstimg.rows;
                    dest.rowBytes=dstimg.cols;
                    vImageScale_Planar8(&src, &dest, NULL, kvImageNoFlags);

For the resampling APIs in vImage/Geometry.h, we chose to use the vector unit to deliver better quality rather than more speed. This is because the vector units are usually pretty poor at doing scattered accesses in memory, which is largely what you are doing for something simple like linear or nearest neighbor resampling with non-unit stride. They didn't seem like they were going to be good at making nearest neighbor or linear filtering go fast. So, instead we went to Lanczos filtering, which looks at a larger region of contiguous pixels to figure out each result pixel. It looks awesome (I think) but it's more work to get the awesomeness.

Also, c'mon if all you want is linear or nearest neighbor filtering, then the GPUs have hardware for that!

It is true that in general APIs in vImage are intended to give you faster results than rolling your own.

cv::resize uses linear interpolation by default. vImageScale_Planar8 uses Lanczos resampling , which is more complex, but also gives significantly better quality. You're comparing apples and oranges.

First, just a comment: normally the height would be rows, and the width columns - its seems odd the way you are using it.

Did you malloc the memory for the destination image:

dstimg.data = malloc(dstimg.cols * dstimg.rows);

You set the deployment target to ios5 or newer?

I've used the Accelerate framework with no problems on iOS5.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM