简体   繁体   English

使用图像像素

[英]Working with image pixels

I'm trying to do a project here, which I want to implement the following: 我正在尝试做一个项目,我想实现以下项目:

I have a rotation matrix and translation matrix are estimated, now I have an image in a certain location and I want to multiply all the image pixel by the rotation matrix and add the results to the translation matrix..... 我有一个旋转矩阵,并且估计了平移矩阵,现在我在某个位置有一个图像,我想将所有图像像素乘以旋转矩阵,然后将结果添加到平移矩阵中.....

My issue is how to work with the pixels? 我的问题是如何使用像素? I mean how to extract the pixel from the image in order to do the operation that I mentioned above? 我的意思是如何从图像中提取像素以执行上面提到的操作?

it's ok to give me the suggestion in either opencv or c++ 可以用opencv或c ++给我建议

* I need to know how to do this operation new_p(x,y) = old_p(x,y)* rotation_matrix + translation_matrix. * 我需要知道如何执行此操作new_p(x,y)= old_p(x,y)* rotation_matrix + translation_matrix。 I'm defining the image like that IplImage(), 3 channel image. 我正在定义像IplImage()这样的图像,即3通道图像。 For now I need to do the geometrical transformation but I don't know how to use old_p(x,y) which mean old pixels* 现在,我需要进行几何变换,但是我不知道如何使用old_p(x,y),这意味着旧像素*

Thank you. 谢谢。

In Opencv, the functions you need are in the "Geometric Image transformations" section of the manual. 在Opencv中,所需的功能在手册的“几何图像转换”部分中。 In your case, as you already have the rotation matrix and the translation, warpAffine is the function of choice ( link to function documentation ). 在您的情况下,由于已经有了旋转矩阵和平移,因此warpAffine是选择的功能( 链接到功能文档 )。 First two columns of the transformation matrix that you pass are the rotation matrix, the third is the translation vector (in case you are not familiar with homogeneous coordinates). 传递的变换矩阵的前两列是旋转矩阵,第三列是平移矢量(以防您不熟悉齐次坐标)。

The basic idea will be that you need a color value for every pixel in the final result image. 基本思想是,您需要为最终结果图像中的每个像素提供一个颜色值。 So you need to find a function which maps a (rotated and translated) pixel onto every (x,y) position of the final result image. 因此,您需要找到一个将(旋转和平移的)像素映射到最终结果图像的每个(x,y)位置的(x,y)

Given a matrix transforming the original image coordinates to target image coordinates, you'll probably end up inverting that transformation and applying that for every target image pixel, plus or minus a few optimizations. 给定一个将原始图像坐标转换为目标图像坐标的矩阵,您可能最终会反转该转换并将其应用于每个目标图像像素,再加上或减去一些优化。

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

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