所以我有一个1024x1024的灰度图像,当我用matlab打开这张图片时,matlab检测到图像是1024x1024 uint8。
问题是当我用android进行图像处理时,我将图像分成几个部分,然后对图像的某些部分进行攻击过程,然后重新组合图像。然后我用matlab打开攻击结果的图像,matlab检测图像大小1024x1024x3 uint8。我尝试使用opencv提供的cvtColor函数更改图像以更改图像通道,但图像仍然被matlab视为3通道。这是使用android完成图像处理之前和之后的示例图像(左:攻击前,右攻击:攻击后)
这是我使用android
实现的名为高斯噪音的攻击函数之一private Bitmap GaussianNoise(Bitmap src, double variance) {
Bitmap hasil = src;
Mat input = new Mat();
Mat imGray = new Mat();
Utils.bitmapToMat(src, input);
Imgproc.cvtColor(input, imGray, Imgproc.COLOR_RGBA2GRAY);
Mat noise = new Mat(imGray.size(), CvType.CV_64F);
Mat resultMat = new Mat();
Core.normalize(imGray, resultMat, 0.0, 1.0, Core.NORM_MINMAX, CV_64F);
Core.randn(noise, 0, Math.sqrt(variance));
Core.add(resultMat, noise, resultMat);
Core.normalize(resultMat, resultMat, 0.0, 1.0, Core.NORM_MINMAX, CV_64F);
resultMat.convertTo(resultMat, imGray.type(), 255, 0);
Utils.matToBitmap(resultMat, hasil);
return hasil;
}
将非常感谢所有形式的协助