缝雕 –访问可可中的像素数据
我想实现 Avidan/Shamir 的接缝雕刻算法。在可以使用核心图像过滤器实现的能量计算阶段之后,我需要计算具有最低能量的接缝,该接缝不能作为核心图像过滤器实现,因为它使用动态编程(并且您无权访问之前用 opengl 着色语言进行的计算)。
所以我需要一种在 Objective-C 可可中有效访问图像像素数据的方法。
省略边界检查的伪代码:
for y in 0..lines(image) do:
for x in 0..columns(image) do:
output[x][y] = value(image, x, y) +
min{ output[x-1][y-1]; output[x][y-1]; output[x+1][y-1] }
I want to implement the seam carving algorithm by Avidan/Shamir. After the energy computing stage which can be implemented using a core image filter, I need to compute the seams with the lowest energy which can't be implemented as a core image filter for it uses dynamic programming (and you don't have access to previous computations in opengl shading language).
So i need a way to access the pixel data of an image efficiently in objective-c cocoa.
Pseudo code omitting boundary checks:
for y in 0..lines(image) do:
for x in 0..columns(image) do:
output[x][y] = value(image, x, y) +
min{ output[x-1][y-1]; output[x][y-1]; output[x+1][y-1] }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
访问图像像素值的最佳方法是使用 CGBitmapContextCreate。关于这一点的重要部分是,当您创建上下文时,您可以传递指针,该指针将用作位图数据的后备存储。这意味着数据将保存像素值,您可以用它们做任何您想做的事情。
因此步骤应该是:
The best way to get access to the pixel values for an image, is to create a CGBitmapContextRef with CGBitmapContextCreate. The important part about this is that when you create the context, you get to pass the pointer in that will be used as the backing store for the bitmap's data. Meaning that data will hold the pixel values and you can do what ever you want with them.
So the steps should be: