- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 Java 程序中,图像被加载到程序中,然后使用离散小波变换进行变换,所得系数用作输出图像的图片数据。
该过程适用于自然图像:/image/q7qVp.jpg
但是,如果我变换例如卡通图像,则近似子带中的暗边缘会出现白点:/image/aRtIR.jpg
这里是forwardDWT的代码:
private int[][] transformPixels(int[][] pixels, int widthHeight) {
double[][] temp_bank = new double[widthHeight][widthHeight];
double a1 = -1.586134342;
double a2 = -0.05298011854;
double a3 = 0.8829110762;
double a4 = 0.4435068522;
// Scale coeff:
double k1 = 0.81289306611596146; // 1/1.230174104914
double k2 = 0.61508705245700002;// 1.230174104914/2
for (int i = 0; i < 2; i++) {
for (int col = 0; col < widthHeight; col++) {
// Predict 1
for (int row = 1; row < widthHeight - 1; row += 2) {
pixels[row][col] += a1 * (pixels[row - 1][col] + pixels[row + 1][col]);
}
pixels[widthHeight - 1][col] += 2 * a1 * pixels[widthHeight - 2][col];
// Update 1
for (int row = 2; row < widthHeight; row += 2) {
pixels[row][col] += a2 * (pixels[row - 1][col] + pixels[row + 1][col]);
}
pixels[0][col] += 2 * a2 * pixels[1][col];
// Predict 2
for (int row = 1; row < widthHeight - 1; row += 2) {
pixels[row][col] += a3 * (pixels[row - 1][col] + pixels[row + 1][col]);
}
pixels[widthHeight - 1][col] += 2 * a3 * pixels[widthHeight - 2][col];
// Update 2
for (int row = 2; row < widthHeight; row += 2) {
pixels[row][col] += a4 * (pixels[row - 1][col] + pixels[row + 1][col]);
}
pixels[0][col] += 2 * a4 * pixels[1][col];
}
for (int row = 0; row < widthHeight; row++) {
for (int col = 0; col < widthHeight; col++) {
if (row % 2 == 0)
temp_bank[col][row / 2] = k1 * pixels[row][col];
else
temp_bank[col][row / 2 + widthHeight / 2] = k2 * pixels[row][col];
}
}
for (int row = 0; row < widthHeight; row++) {
for (int col = 0; col < widthHeight; col++) {
pixels[row][col] = (int) temp_bank[row][col];
}
}
}
return pixels;
}
这是使用提升方案实现的 CDF9/7 fitlerbanks 的 DWT,类似于 JPEG2000 中的 DWT。
该算法有两个局限性:
因为也可能是灰度值计算错误,这里是加载图像、启动转换、将 RGB 值转换为灰度以及转换回 RGB 的其他代码:
public BufferedImage openImage() throws InvalidWidthHeightException {
try {
int returnVal = fc.showOpenDialog(panel);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
BufferedImage temp = ImageIO.read(file);
if (temp == null)
return null;
int checkInt = temp.getWidth();
boolean check = (checkInt & (checkInt - 1)) == 0;
if (checkInt != temp.getHeight() & !check)
throw new InvalidWidthHeightException();
int widthandHeight = temp.getWidth();
image = new BufferedImage(widthandHeight, widthandHeight, BufferedImage.TYPE_BYTE_GRAY);
Graphics g = image.getGraphics();
g.drawImage(temp, 0, 0, null);
g.dispose();
return image;
}
} catch (IOException e) {
System.out.println("Failed to load image!");
}
return null;
}
public void transform(int count) {
int[][] pixels = getGrayValues(image);
int transformedPixels[][];
int width = pixels.length;
transformedPixels = transformPixels(pixels, width);
width/=2;
for (int i = 1; i < count + 1; i++) {
transformedPixels = transformPixels(transformedPixels, width);
width/=2;
}
width = pixels.length;
transformedImage = new BufferedImage(width, width, BufferedImage.TYPE_BYTE_GRAY);
for (int x = 0; x < width; x++) {
for (int y = 0; y < width; y++) {
transformedImage.setRGB(x, y, tranformToRGB(transformedPixels[x][y]));
}
}
}
private int tranformToRGB(double d) {
int value = (int) d;
if (d < 0)
d = 0;
if (d > 255)
d = 255;
return 0xffffffff << 24 | value << 16 | value << 8 | value;
}
private int[][] getGrayValues(BufferedImage image2) {
int[][] res = new int[image.getHeight()][image.getWidth()];
int r, g, b;
for (int i = 0; i < image.getWidth(); i++) {
for (int j = 0; j < image.getHeight(); j++) {
int value = image2.getRGB(i, j);
r = (value >> 16) & 0xFF;
g = (value >> 8) & 0xFF;
b = (value & 0xFF);
res[i][j] = (r + g + b) / 3;
}
}
return res;
}
注意:因为图像的宽度和高度预计是相同的,所以有时我也使用宽度来表示高度。
编辑:根据@stuhlo的建议,我添加了对forwardDWT中近似子带值的检查:
for (int row = 0; row < widthHeight; row++) {
for (int col = 0; col < widthHeight; col++) {
if (row % 2 == 0) {
double value = k1 * pixels[row][col];
if (value > 255)
value = 255;
if (value < 0)
value = 0;
temp_bank[col][row / 2] = value;
} else {
temp_bank[col][row / 2 + widthHeight / 2] = k2 * pixels[row][col];
}
}
}
不幸的是,现在水平细节的子区域变成黑色。
最佳答案
您的问题是由于子带样本需要比原始图像样本更多的位数来存储而引起的。
我建议使用更大的数据类型来存储子带样本并将其标准化回 8 位值以进行显示。
关于java - Java 中的离散小波变换在图像中创建白点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38370691/
我正在寻找一种简单的解决方案来将对象从一个地方移动和缩放到另一个地方。 我做了一个JSfiddle用这个代码。问题是我需要它在某个时刻停止变小。所以它有一个最小尺寸,另一个问题是我希望它既缩小又向左移
我正在尝试通过沿 x 轴上下翻转(180 度)来为悬停时的图像设置动画。 就像here 除非我出于某种原因无法让它工作。 img { transition:all 2s ease-in-out
我想实例化一个 slider 约束,它允许 body 在 A 点和 B 点之间滑动。 为了实例化约束,我指定了两个物体进行约束,在这种情况下,一个动态物体被约束到静态世界,比如滑动门。 第三个和第四个
我想使用此功能旋转然后停止在特定点或角度。现在该元素只是旋转而不停止。代码如下: $(function() { var $elie = $("#bkgimg");
我正在尝试使用 CATransform3D 向 View 添加透视图。目前,这就是我得到的: 这就是我想要得到的: 我很难做到这一点。我完全迷失在这里。这是我的代码: CATransform3D t
我编写了一个图形用户界面,用户可以在其中在 (640x480) 窗口中绘制内容。它使该绘图成为一组存储在 Vector 数组中的点。 现在,我如何将这些点集平移到原点(0,0 窗口左上角)或将其放在指
我的应用程序中有两张图像相互叠加,分别表示为 foreground 和 background。对于这两个,我都使用 background-attachment: fixed 来确保图像始终彼此完全相同
如何在不损失质量的情况下应用旋转变换?我试过添加 translateZ(0) 但它无济于事。这是例子: svg { background-color: rgb(93, 193, 93); }
我有一个 div,我试图在悬停时缩放它(只是 Y)。问题是它在没有过渡的情况下运行良好。当我使用过渡时,div 在顶部缩放一点然后下降,检查 fiddle 。问题是如何防止 div 那样缩放?我希望它
我正在尝试使用 transform: scale 图像网格 http://movies.themodern-nerd.com/genre .从左向右滚动时它工作正常,悬停的图像将停留在其他图像之上,但
我正在查看 CSS3 Transform 并且想要一个既倾斜又旋转的盒子。 我试过使用: transform:rotate(80deg); -moz-transform:rotate(80deg);
当用户在图像父元素上执行 mousemove 时,我试图在 img 上添加平滑移动效果(此处为 .carousel-img)但我无法正常运行它。 我做错了什么? $('.carousel-img').
我有 div 元素在其他 div 元素中垂直对齐。 我使用以下方法对齐它们:position: relative;变换:翻译Y(-50%);顶部:50%。这很好用。 我现在想缩放元素(使用 jQuer
我在这个 fiddle 中使用 RotateX 后创建了 3D 效果: http://jsfiddle.net/vEWEL/11/ 但是,我不确定如何在这个 Fiddle 中的红色方 block 上实
使用 transform: scale(x.x) 而不是使用 width 和 height 属性进行传统的调整大小有什么缺点吗?缩放会产生质量较低的图像或其他什么吗? 最佳答案 Scale 生成总体上
我在一个点上有一个对象,比如相对于原点的 x、y、z。 我想对点应用一些变换,比如旋转和平移,并在变换后的点渲染对象。我正在使用 glTranslatef() 和 glRotatef() 函数。它看起
有没有办法将转换应用到插入了 :before 的元素上? 以下方法无效,但我愿意接受其他解决方案。 .itemclass:before { content: "➨"; transform:
我找到了这个:width/height after transform 和其他几个,但没有什么不是我正在寻找的。我想要的是将某些东西缩放到其大小的 50%(当然还有漂亮的动画过渡)并让页面布局重新调整
我想使用变换为元素位置设置动画。我怎么能在这个翻译中添加一些曲线(没什么特别的,只是不是一条完整的直线)?对于 jquery,我会使用效果很好的 easeInSine。 var a = documen
我试着写一个 TransformMesh功能。该函数接受一个 Mesh对象和 Matrix目的。这个想法是使用矩阵来转换网格。为此,我锁定了顶点缓冲区,并在每个顶点上调用了 Vector3::Tran
我是一名优秀的程序员,十分优秀!