UV coordinates to Pixel coordinates
Posted d1012181765
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UV coordinates to Pixel coordinates相关的知识,希望对你有一定的参考价值。
pix.x = (uv.x * texture.width) -0.5
pix.y = ((1-uv.y) * texture.height) -0.5
uv坐标的y轴与图像上的像素坐标相反
对于最近的邻插值,只需舍入像素坐标
对于双线性插值,请从四个相邻像素计算参与百分比并进行加权平均
当UV坐标超出范围时,可以选择如何处理“纹理包裹”:opengl texture Wrapping
这是一些带有“重复”纹理包装的双线性插值的Java代码:
private static int billinearInterpolation(Point2D uv, BufferedImage texture) { uv.x = uv.x>0 ? uv.x%1 : 1+(uv.x%1); uv.y = uv.y>0 ? uv.y%1 : 1+(uv.y%1); double pixelXCoordinate = uv.x * texture.getWidth() - 0.5; double pixelYCoordinate = (1-uv.y) * texture.getHeight() - 0.5; pixelXCoordinate = pixelXCoordinate<0?texture.getWidth()-pixelXCoordinate: pixelXCoordinate; pixelYCoordinate = pixelYCoordinate<0?texture.getHeight()-pixelYCoordinate : pixelYCoordinate; int x = (int) Math.floor(pixelXCoordinate); int y = (int) Math.floor(pixelYCoordinate); double pX = pixelXCoordinate - x; double pY = pixelYCoordinate - y; float[] px = new float[]{(float) (1 - pX), (float) pX}; float[] py = new float[]{(float) (1 - pY), (float) pY}; float red = 0; float green = 0; float blue = 0; float alpha = 0; for (int i = 0; i < px.length; i++) { for (int j = 0; j < py.length; j++) { float p = px[i] * py[j]; if (p != 0) { int rgb = texture.getRGB((x + i)%texture.getWidth(), (y + j)%texture.getHeight()); alpha += (float) ((rgb >> 24) & 0xFF) * p; red += (float) ((rgb >> 16) & 0xFF) * p; green += (float) ((rgb >> 8) & 0xFF) * p; blue += (float) ((rgb >> 0) & 0xFF) * p; } } } return (((int) alpha & 0xFF) << 24) | (((int) red & 0xFF) << 16) | (((int) green & 0xFF) << 8) | (((int) blue & 0xFF) << 0); }
以上是关于UV coordinates to Pixel coordinates的主要内容,如果未能解决你的问题,请参考以下文章
Get a specific pixel coordinates where your mouse on (cc)
labelme_json_to_dataset不能转换关键点的问题(coordinate list must contain at least 2 coordinates)解决办法
FlinkFailed to create checkpoint storage at checkpoint coordinator side
《Learning to Coordinate with Coordination Graphs in Repeated Single-Stage Multi-Agent Decision Probl
象素shader入门(Introduction to Pixel Shaders)
RuntimeError: The following handlers are available to decode the pixel data however they are missing