- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试使用 JTransform 获取 bufferedImage 的 DCT。当我可视化转换时,它当前看起来像这样 http://tinypic.com/r/2vcxhzo/8
为了使用 Jtransform,我需要将 BufferedImage 转换为 2d double 组。我尝试了两种不同的方法将 bufferedImage 更改为双数组
public double[][] convertTo2DArray(BufferedImage image) {
final byte[] pixels = ((DataBufferByte) image.getRaster()
.getDataBuffer()).getData();
final int width = image.getWidth();
final int height = image.getHeight();
double[][] result = new double[height][width];
final boolean hasAlphaChannel = image.getAlphaRaster() != null;
if (hasAlphaChannel) {
final int pixelLength = 4;
for (int pixel = 0, row = 0, col = 0; pixel < pixels.length; pixel += pixelLength) {
int argb = 0;
argb += (((int) pixels[pixel] & 0xff) << 24); // alpha
argb += ((int) pixels[pixel + 1] & 0xff); // blue
argb += (((int) pixels[pixel + 2] & 0xff) << 8); // green
argb += (((int) pixels[pixel + 3] & 0xff) << 16); // red
result[row][col] = argb;
col++;
if (col == width) {
col = 0;
row++;
}
}
} else {
final int pixelLength = 3;
for (int pixel = 0, row = 0, col = 0; pixel < pixels.length; pixel += pixelLength) {
int argb = 0;
argb += -16777216; // 255 alpha
argb += ((int) pixels[pixel] & 0xff); // blue
argb += (((int) pixels[pixel + 1] & 0xff) << 8); // green
argb += (((int) pixels[pixel + 2] & 0xff) << 16); // red
result[row][col] = argb;
col++;
if (col == width) {
col = 0;
row++;
}
}
}
return result;
}
我也尝试过
private double[][] bufferedImageToArray(BufferedImage image) {
int h = image.getHeight();
int w = image.getWidth();
int[][] array = new int[h][w];
double[][] result;
for (int count = 0; count < h; count++) {
for (int loop = 0; loop < w; loop++) {
int gray = image.getRGB(loop, count) & 0xFF;
// add values to array
array[count][loop] = gray;
}
}
result = toDoubleArray(array);
return result;
}
我已将转换实现为
public double[][] applyDCT(double[][] image) {
DoubleDCT_2D transform = new DoubleDCT_2D(image.length, image[0].length);
transform.forward(image, true);
return image;
}
我尝试使用 OpenCV 的 dct 变换,但它给出的输出与链接中所示的相同。
最佳答案
类似的东西(为了简单起见,我只保留了蓝色 channel )。它在结果图像的左上角显示了能量压缩。
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class TestDCT
{
public static void main(String[] args)
{
ImageIcon icon = new ImageIcon(args[0]);
Image image = icon.getImage();
int w = image.getWidth(null);
int h = image.getHeight(null);
GraphicsDevice gs = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0];
GraphicsConfiguration gc = gs.getDefaultConfiguration();
BufferedImage img = gc.createCompatibleImage(w, h, Transparency.OPAQUE);
img.getGraphics().drawImage(image, 0, 0, null);
int[] rgb1 = new int[w*h];
img.getRaster().getDataElements(0, 0, w, h, rgb1);
double[] array = new double[w*h];
for (int i=0; i<w*h; i++)
array[i] = (double) (rgb1[i] & 0xFF);
org.jtransforms.dct.DoubleDCT_2D tr = new org.jtransforms.dct.DoubleDCT_2D(w, h);
tr.forward(array, true);
for (int i=0; i<w*h; i++)
{
// Grey levels
int val= Math.min((int) (array[i]+128), 255);
rgb1[i] = (val <<16) | (val << 8) | val;
}
img.getRaster().setDataElements(0, 0, w, h, rgb1);
icon = new ImageIcon(img);
JFrame frame = new JFrame("FFT");
frame.setBounds(20, 30, w, h);
frame.add(new JLabel(icon));
frame.setVisible(true);
}
}
关于java - 使用 JTransform 对缓冲图像进行 DCT - Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29320121/
当我使用 jTransform 时。 https://sites.google.com/site/piotrwendykier/software/jtransforms 用我的应用程序对我的 pcm
我正在为 Google Glass 开发一个应用程序,该应用程序自录制音频以来实时显示峰值电流峰值频率。我当前的问题是频率报告变化非常快,因此很难确定频率我也不确定我的 NumberFormat 输出
我有一张图像,我想使用 FFT 将其转换为频域,Java 似乎缺少这方面的库,但我找到了两个。一个是 JTransforms,另一个不太知名,没有名字。 对于不太知名的 2D 只能具有二次幂的长度值,
我正在使用 Jtransforms java 库对给定的数据集执行分析。 数据示例如下: 980,988,1160,1080,928,1068,1156,1152,1176,1264 我在 jTran
鉴于我只想选择频率,我正在尝试计算逆 FFT。以下是我进行 FFT 的方法: final double[] points = reader.readPoints(); final DoubleFFT_
我一直在寻找快速和完整的 DSP java 库来与 android 音频操作一起使用。我对 FFT 的高度计算有疑问。然后我找到了 JTransforms。我无法在任何地方找到有关如何使用它的文档。具
我正在尝试使用 jTransforms 库对 WAV 文件进行频谱分析:Official Site 但是我在如何使用 jTransforms 将 WAV 文件转换为 FFT 可接受的输入以及如何在 F
我一直在阅读 SO 中有关 FTT 和使用 JTransform 的所有帖子。我有一个真实数据,它的大小为 N。我想将它传递给 FFT,以便我可以计算每个频率的幅度。 我已经使用 FFT 函数在 ma
我正在使用 JTransforms realForwardFull 和 RealInverse 来测试它们的工作原理。我的理解是,在您将音频信号传递给 realForwardFull 然后应用 Rea
我想展示一些PCM数据的可视化效果。目标是显示如下内容: 我搜索并发现 JTransform 是正确的库。但是,我找不到如何使用这个库的好指南。如何将我的 PCM 数据转换为可用于绘制条形的频带/频率
我正在尝试将 JTransforms-3.0-javadoc.jar 文件包含到我在 android studio 中的项目中,并在这里查看了类似的问题,但我似乎没有任何运气。这里有人知道让它工作所需
我想做的是用 Java 计算图像的 2D DCT,然后将结果保存回文件。 读取文件: coverImage = readImg(coverPath); private BufferedImage re
我正在尝试使用 JTransform 获取 bufferedImage 的 DCT。当我可视化转换时,它当前看起来像这样 http://tinypic.com/r/2vcxhzo/8 为了使用 Jtr
我正在尝试使用以下代码计算时间序列中样本窗口的自相关。我正在对该窗口应用 FFT,然后计算实部和虚部的大小并将虚部设置为零,最后对其进行逆变换以获得自相关: DoubleFFT_1D fft = ne
我正在使用 Java 中的 JTransforms 中的 DoubleFFT_1D.realForward() 来处理示例。 有谁知道这个方法输入的double[] a的长度是否必须是2的幂?在 JT
我尝试对长度为4000的输入信号进行FFT。我的java代码如下: Vector signal = readFile("signal.txt"); double[] input = n
我目前正在使用 JTransforms 库来计算 FS 为 44100 Hz 的一秒信号的 DFT。代码非常简单: DoubleFFT_1D fft = new DoubleFFT_1D(SIZE);
我有时域数据样本,这些样本不断更新名为“rollHistory”的 LinkedList,然后显示在图中,如下所示: if (rollHistory.size() > HISTORY_SIZE) {
我对任意长度的数组执行 FFT。API可以引用如下: realForward public void realForward(double[] a) Computes 1D forward DFT o
我正在尝试为 JTransforms 安装库。我从这里下载了 .jar 文件:https://sites.google.com/site/piotrwendykier/software/jtransf
我是一名优秀的程序员,十分优秀!