Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 图像大小调整双线性插值和最近邻_Java_Algorithm_Image Processing_Graphics - Fatal编程技术网

Java 图像大小调整双线性插值和最近邻

Java 图像大小调整双线性插值和最近邻,java,algorithm,image-processing,graphics,Java,Algorithm,Image Processing,Graphics,我目前在提出重新缩放和图像的算法时遇到了问题。 我目前想实现双线性插值和最近邻插值。我理解它们在概念上是如何工作的,但我似乎无法将其记录到代码中。我仍然被困在最近的邻居那里 我在下面为它编写了一些伪代码(根据我所知): 我的原始数据集(从中获取数据量)存储在带有[x][y][z]和(x,y,z)的3D数组中。我分别读取每个像素,并可以使用java中的Color.Color计算每个像素的颜色。但是,我需要知道如何获得每个像素位置x和y(x,y)的颜色(c=[0,1,2]),不包括z(对于一个视图)

我目前在提出重新缩放和图像的算法时遇到了问题。 我目前想实现双线性插值和最近邻插值。我理解它们在概念上是如何工作的,但我似乎无法将其记录到代码中。我仍然被困在最近的邻居那里 我在下面为它编写了一些伪代码(根据我所知):

我的原始数据集(从中获取数据量)存储在带有[x][y][z]和(x,y,z)的3D数组中。我分别读取每个像素,并可以使用java中的Color.Color计算每个像素的颜色。但是,我需要知道如何获得每个像素位置x和y(x,y)的颜色(c=[0,1,2]),不包括z(对于一个视图),以便将每个新像素的1个旧像素转换为包含新宽度和高度的新数据集。我已经用Java编写了上面翻译的大部分代码。但我仍然不明白如何最终确定一个可行的实施方案


提前感谢我对java不是很熟悉。但是这里有一个python的工作代码

import cv2
import numpy as np

img = cv2.imread("image.png")
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

scaleX = 0.5
scaleY = 0.5

newImg = np.zeros((int(img.shape[0]*scaleX),int(img.shape[1]*scaleY))).astype(np.uint8)

for y in range(newImg.shape[0]):
    for x in range(newImg.shape[1]):
        samplex = x/scaleX
        sampley = y/scaleY
        dx = samplex - np.floor(samplex)
        dy = sampley - np.floor(sampley)

        val = img[int(sampley-dy),int(samplex-dx)]*(1-dx)*(1-dy)
        val += img[int(sampley + 1 - dy),int(samplex-dx)]*(1-dx)*(dy) 
        val += img[int(sampley-dy),int(samplex + 1 - dx)]*(dx)*(1-dy)
        val += img[int(sampley + 1 -dy),int(samplex + 1 - dx)]*(dx)*(dy)

        newImg[y,x] = val.astype(np.uint8)


cv2.imshow("img",newImg)
cv2.waitKey(0)

您只需在for中再添加一个for循环,并添加x for循环来解释通道。

我对java不是很熟悉。但是这里有一个python的工作代码

import cv2
import numpy as np

img = cv2.imread("image.png")
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

scaleX = 0.5
scaleY = 0.5

newImg = np.zeros((int(img.shape[0]*scaleX),int(img.shape[1]*scaleY))).astype(np.uint8)

for y in range(newImg.shape[0]):
    for x in range(newImg.shape[1]):
        samplex = x/scaleX
        sampley = y/scaleY
        dx = samplex - np.floor(samplex)
        dy = sampley - np.floor(sampley)

        val = img[int(sampley-dy),int(samplex-dx)]*(1-dx)*(1-dy)
        val += img[int(sampley + 1 - dy),int(samplex-dx)]*(1-dx)*(dy) 
        val += img[int(sampley-dy),int(samplex + 1 - dx)]*(dx)*(1-dy)
        val += img[int(sampley + 1 -dy),int(samplex + 1 - dx)]*(dx)*(dy)

        newImg[y,x] = val.astype(np.uint8)


cv2.imshow("img",newImg)
cv2.waitKey(0)

您只需在for和x for循环中添加一个for循环来解释通道。

如果我正确,在这种情况下,您是在插值体积(体素),而不是像素: 让我们使用源卷
vol1[xs1][ys1][zs1]
和目标卷
vol0[xs0][ys0][zs0]
其中
xs、ys、zs
是最近邻的分辨率:


//vol0如果我没弄错,在这种情况下,你是在插值体积(体素),而不是像素:
让我们使用源卷
vol1[xs1][ys1][zs1]
和目标卷
vol0[xs0][ys0][zs0]
其中
xs、ys、zs
是最近邻的分辨率:


//它们是像素。我有一个三维数组,根据x、y和z位置存储每个像素。因此,与其说是体积,不如说是图像[][]@BrevynKurt,这种数据称为体积数据,而持有颜色的单个3D单元称为体素,而不是像素。。。要区分3D和2D…它们是像素。我有一个三维数组,根据x、y和z位置存储每个像素。因此,与其说是体积,不如说是图像[][]@BrevynKurt,这种数据称为体积数据,而持有颜色的单个3D单元称为体素,而不是像素。。。要区分3D和2D。。。