Java DCT隐写术

Java DCT隐写术,java,image,image-processing,steganography,dct,Java,Image,Image Processing,Steganography,Dct,我正在尝试完成DCT隐写术项目,并且出现了一些关于它的问题。有人能帮我吗?我所做的: 1) 将图像分割为8x8像素 public BufferedImage[] getBlocksOfImage(BufferedImage image){ int width = image.getWidth(); int height = image.getHeight(); int arrayIndex = 0; //TODO specify dynamic length

我正在尝试完成DCT隐写术项目,并且出现了一些关于它的问题。有人能帮我吗?我所做的:

1) 将图像分割为8x8像素

public BufferedImage[] getBlocksOfImage(BufferedImage image){
    int width = image.getWidth();
    int height = image.getHeight();
    int arrayIndex = 0;
    //TODO specify dynamic length
    //TODO for 512x512 --> 4096 (8x8 block)
    BufferedImage[] blocksOfImage = new BufferedImage[4096];
    for (int i = 0; i<width; i=i+8) {
        for (int j = 0; j<height; j=j+8) {
            blocksOfImage[arrayIndex] = image.getSubimage(i,j,8,8);
            arrayIndex++;
        }
    }
    return blocksOfImage;
}
public BufferedImage[]getBlocksOfImage(BufferedImage图像){
int width=image.getWidth();
int height=image.getHeight();
int-arrayIndex=0;
//TODO指定动态长度
//512x512-->4096(8x8块)的TODO
BuffereImage[]blocksOfImage=新的BuffereImage[4096];

对于(int i=0;i来说,您似乎正在尝试进行JPEG隐写术。编写JPEG编码器的标准非常复杂,因此更容易借用已编写的编码器,并进行任何小的修改以将隐藏算法插入其中

我有一个类似的问题,我简要总结了算法的关键点,并展示了一个java示例

关于这个过程的一个很好的开始是在维基百科上。这应该可以回答你提出的所有问题,但我也会在这里解决它们

我应该将什么传递到GetDTCtrTransformMatrix()函数中?现在我传递的是像素的整数值,我认为这是错误的。我见过一些例子,其中有人传递0-255之间的值,所以我应该将图像转换为灰度级吗?还是应该对每种颜色(R、G、B)进行转换

是的,您可以单独传递每个颜色平面的整数值。这可以是RGB或YCrCb。它也可以是0-255,也可以是以0为中心,即-127128。YCrCb被首选的原因是,由于我们的眼睛如何工作,一些通道可以被压缩得更多,而不会出现任何明显的质量损失。以及移动ran以0为中心的数字的ge意味着得到的DCT系数将具有较小的值,并且需要较少的比特来存储

在执行GetDTCtrTransformMatrix()之后,我得到了double的矩阵。如何以double值编辑LSB?这是正确的方法吗

这是JPEG编码的要点。你应该量化系数(把它们变成整数)有一个特定的量化矩阵。虽然有一个默认矩阵,但各种程序都选择使用自定义矩阵。其思想是低频系数不会受到太大影响,而大多数高频系数可能会变为0,这有助于最终文件大小变小。这是一个有损过程,您应该嵌入您的信息在量化系数之后,由于剩下的步骤都是无损的,因此需要执行以下操作

在我将LSB更改为双倍值后,我接下来应该做什么?如何确保信息将存储在图像中


在1D中以之字形排列系数,使低频系数排在第一位。然后使用游程长度和哈夫曼编码的组合将该信息存储在文件中。文件的二进制数据与原始像素都不相似(显然)或者DCT系数的值。这是系数的压缩数据。

看起来你在尝试JPEG隐写术。编写JPEG编码器的标准涉及面很广,因此更容易借用已经编写好的编码器,并进行任何小的修改,将隐藏算法注入其中

我有一个类似的问题,我简要总结了算法的关键点,并展示了一个java示例

关于这个过程的一个很好的开始是在维基百科上。这应该可以回答你提出的所有问题,但我也会在这里解决它们

我应该将什么传递到GetDTCtrTransformMatrix()函数中?现在我传递的是像素的整数值,我认为这是错误的。我见过一些例子,其中有人传递0-255之间的值,所以我应该将图像转换为灰度级吗?还是应该对每种颜色(R、G、B)进行转换

是的,您可以单独传递每个颜色平面的整数值。这可以是RGB或YCrCb。它也可以是0-255,也可以是以0为中心,即-127128。YCrCb被首选的原因是,由于我们的眼睛如何工作,一些通道可以被压缩得更多,而不会出现任何明显的质量损失。以及移动ran以0为中心的数字的ge意味着得到的DCT系数将具有较小的值,并且需要较少的比特来存储

在执行GetDTCtrTransformMatrix()之后,我得到了double的矩阵。如何以double值编辑LSB?这是正确的方法吗

这是JPEG编码的要点。你应该量化系数(把它们变成整数)有一个特定的量化矩阵。虽然有一个默认矩阵,但各种程序都选择使用自定义矩阵。其思想是低频系数不会受到太大影响,而大多数高频系数可能会变为0,这有助于最终文件大小变小。这是一个有损过程,您应该嵌入您的信息在量化系数之后,由于剩下的步骤都是无损的,因此需要执行以下操作

在我将LSB更改为双倍值后,我接下来应该做什么?如何确保信息将存储在图像中


在1D中以之字形排列系数,使低频系数排在第一位。然后使用游程长度和哈夫曼编码的组合将该信息存储在文件中。文件的二进制数据与原始像素都不相似(显然)或者DCT系数的值。这是系数的压缩数据。

谢谢你的回答。我会看一遍,让你知道。谢谢。谢谢你的回答。我会看一遍,让你知道。谢谢。
//get matrix of pixels (used in DCT]
public int[][] getMatrixPixels(BufferedImage image){
    int[][] matrixPixels = new int[image.getWidth()][image.getHeight()];
    for (int i = 0; i < matrixPixels[0].length; i++) {
        for (int j = 0; j < matrixPixels.length; j++) {
            matrixPixels[i][j] = image.getRGB(i, j);
        }
    }
    return matrixPixels;
}
public double[][] getDTCTransformMatrix(int[][] imageMatrix){

    double[][] dctTransformMatrix = new double[m][n];
    double ci, cj, tmpDCTValue, tmpSum;
    tmpSum = 0;

    //TODO simplify 4x for --> BAD
    //TODO consulting
    for(int i = 0; i<m; i++) {
        for(int j = 0; j<n; j++) {

            if (i == 0){
                ci = 1 / Math.sqrt(m);
            } else {
                ci = Math.sqrt(2) / Math.sqrt(m);
            }
            if (j == 0){
                cj = 1 / Math.sqrt(n);
            } else {
                cj = Math.sqrt(2) / Math.sqrt(m);
            }

            for (int i_image = 0; i_image < m; i_image++) {
                for (int j_image = 0; j_image < n; j_image++) {

                    tmpDCTValue = imageMatrix[i_image][j_image] *
                            Math.cos((2 * i_image + 1) * i * Math.PI / (2 * m)) *
                            Math.cos((2 * j_image + 1) * j * Math.PI / (2 * n));
                    tmpSum += tmpDCTValue;
                }
            }
            dctTransformMatrix[i][j] = ci * cj * tmpSum;
        }
    }
    return dctTransformMatrix;
}
public int[][] getQuantiseCoefficients(double[][] DTCTransformMatrix) {
    int[][] quantiseResult = new int[DTCTransformMatrix.length][DTCTransformMatrix[1].length];
    int[][] quantiseMatrix =   {{16, 11, 10, 16, 24, 40, 51, 61},
                                {12, 12, 14, 19, 26, 58, 60, 55},
                                {14, 13, 16, 24, 40, 57, 69, 56},
                                {14, 17, 22, 29, 51, 87, 80, 62},
                                {18, 22, 37, 56, 68, 109, 103, 77},
                                {24, 35, 55, 64, 81, 104, 113, 92},
                                {49, 64, 78, 87, 103, 121, 120, 101},
                                {72, 92, 95, 98, 112, 100, 103, 99}};

    //TODO delete static 8
    for (int i = 0; i<8; i++) {
        for (int j = 0; j<8; j++) {
            //Bij = round(Gij/Qij)
            quantiseResult[i][j] = (int)Math.round(DTCTransformMatrix[i][j]/quantiseMatrix[i][j]);
        }
    }
    return quantiseResult;
}
public ArrayList<int[][]> addMessageFirst(ArrayList<int[][]> quantiseMatrixRGB, String message) {
    Utils utils = new Utils();
    int bitTextShift = 7;
    int byteTextShift = 0;
    byte[] textByteArray = text.getBytesFromText(message);

    for (int i = 0; i < textByteArray.length*8; i++) {
        byte[] firstValueByte = utils.integerToByte(quantiseMatrixRGB.get(i)[0][0]);

        firstValueByte[3] = (byte) ((firstValueByte[3] & 0xFE) | ((int) textByteArray[byteTextShift] >>> bitTextShift) & 1);
        if (bitTextShift <= 0) {
            bitTextShift = 7;
            byteTextShift++;
        } else {
            bitTextShift--;
        }
    }
    return quantiseMatrixRGB;
}
public int[][] revertGetQuantiseCoefficients (int[][] quantiseMatrixRGB) {
    int[][] quantiseMatrix =   {{16, 11, 10, 16, 24, 40, 51, 61},
                                {12, 12, 14, 19, 26, 58, 60, 55},
                                {14, 13, 16, 24, 40, 57, 69, 56},
                                {14, 17, 22, 29, 51, 87, 80, 62},
                                {18, 22, 37, 56, 68, 109, 103, 77},
                                {24, 35, 55, 64, 81, 104, 113, 92},
                                {49, 64, 78, 87, 103, 121, 120, 101},
                                {72, 92, 95, 98, 112, 100, 103, 99}};
    for (int j = 0; j<8; j++) {
        for (int k = 0; k<8; k++) {
            quantiseMatrixRGB[j][k]=quantiseMatrixRGB[j][k]*quantiseMatrix[j][k];
        }
    }
    return quantiseMatrixRGB;
}

public int[][] revertGetDTCTransformMatrix(int[][] quantiseMatrixRGB) {
    double[][] dctTransformMatrix = new double[m][n];
    double ck, cl, tmpDCTValue, tmpSum;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                tmpSum = 0;
                for (int i_image = 0; i_image < m; i_image++) {
                    for (int j_image = 0; j_image < n; j_image++) {

                        if (i_image == 0) {
                            ck = 1 / Math.sqrt(m);
                        } else {
                            ck = Math.sqrt(2) / Math.sqrt(m);
                        }
                        if (j_image == 0) {
                            cl = 1 / Math.sqrt(n);
                        } else {
                            cl = Math.sqrt(2) / Math.sqrt(n);
                        }

                        tmpDCTValue = quantiseMatrixRGB[i_image][j_image] *
                                Math.cos((2 * i_image + 1) * i * pi / (2 * m)) *
                                Math.cos((2 * j_image + 1) * j * pi / (2 * n));
                        tmpSum = tmpSum + ck*cl*tmpDCTValue;
                    }
                }
                dctTransformMatrix[i][j] =  tmpSum;
            }
        }
    return quantiseMatrixRGB;
}

public int[][] getMergeRGB (int[][] r, int[][] g, int[][] b) {
    int[][] mergeRGB = new int[r.length][r[1].length];
    for (int i = 0; i<8; i++) {
        for(int j = 0; j<8; j++) {
            mergeRGB[i][j] = r[i][j];
            mergeRGB[i][j] = (mergeRGB[i][j]<<8) + g[i][j];
            mergeRGB[i][j] = (mergeRGB[i][j]<<8) + b[i][j];
        }
    }
    return mergeRGB;
}

public BufferedImage getPixelBlock (int[][] mergeRGB) {
    BufferedImage bi = new BufferedImage( 8, 8, BufferedImage.TYPE_INT_RGB );
    final int[] a = ( (DataBufferInt) bi.getRaster().getDataBuffer() ).getData();
    System.arraycopy(mergeRGB, 0, a, 0, mergeRGB.length);
    return bi;
}

public BufferedImage joinImages (BufferedImage subImage) {


    return null;
}
}