简体   繁体   English

如何使用加速框架(vImage)缩放灰度图像

[英]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. 嗨,我需要快速缩放灰度图像,所以我尝试了vImage,应用程序崩溃,请帮忙。 In the below code srcimg.data/dstimg.data is a point to unsigned char image data(single channel only gray data). 在下面的代码中,srcimg.data/dstimg.data是指向unsigned char图像数据(单通道仅灰色数据)。

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. 对于vImage / Geometry.h中的重采样API,我们选择使用向量单元来提供更好的质量而不是更快的速度。 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. 所以,我们转而使用Lanczos过滤,它会查看更大的连续像素区域,以找出每个结果像素。 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! 此外,如果你想要的只是线性或最近邻滤波,那么GPU就有了硬件!

It is true that in general APIs in vImage are intended to give you faster results than rolling your own. 确实,通常,vImage中的API旨在为您提供比滚动自己更快的结果。

cv::resize uses linear interpolation by default. cv::resize默认使用线性插值。 vImageScale_Planar8 uses Lanczos resampling , which is more complex, but also gives significantly better quality. vImageScale_Planar8使用Lanczos重采样 ,它更复杂,但也提供了更好的质量。 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: 你是否为目标图像malloc内存:

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

You set the deployment target to ios5 or newer? 您将部署目标设置为ios5或更高版本?

I've used the Accelerate framework with no problems on iOS5. 我在iOS5上使用了Accelerate框架没有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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