我正在尝试使用以下代码将图像的R通道绘制为热图:
// Read image as a Mat of 32bit float
Mat imgMain = new Mat(n_height, n_width, CvType.CV_32FC4);
image = BitmapFactory.decodeFile("img.jpg");
Utils.bitmapToMat(image, imgMain);
imgMain.convertTo(imgMain, CvType.CV_32FC4);
// Extract R channel
Mat imgChR = new Mat(n_height, n_width, CvType.CV_32FC1);
extractChannel(imgMain, imgChR, 0);
// imgChR processed with floating point arithmetic
// Convert to HeatMap
normalize(imgChR, imgChR, 0, 1, NORM_MINMAX);
Mat heatOut = new Mat(n_height, n_width, CvType.CV_8UC4);
applyColorMap(imgChR, heatOut, COLORMAP_JET);
// Save as Image
pimage = Bitmap.createBitmap(n_width, n_height, Bitmap.Config.ARGB_8888);
Utils.matToBitmap(heatOut, pimage);
File f = new File("heat.jpeg");
FileOutputStream fos = new FileOutputStream(f);
pimage.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.close();
为了平均图像的多个副本,我将矩阵从整数转换为浮点数。 (平均过程在以下代码中抽象,但请注意,类型必须转换为32位浮点数) 使用以下代码,我只得到一个黑色图像。
这是绘制单个通道矩阵的热图的正确方法吗? 如果没有,是否还有其他功能或方法可以使用? (当我检查heatOut的类型时,函数返回0作为Mat类型的整数表示。)