0

我正在开发一个用于单击图像并将位图转换为二进制的应用程序。这是我将图像转换为二进制的一些代码:

    File file = new  File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Watershed/WatershedImages", "Image_"+Save.MyDate+".jpg");
    Mat origianlImage = Imgcodecs.imread(file.getAbsolutePath());
    Mat image1Mat = new Mat();
    Imgproc.cvtColor(origianlImage,image1Mat, Imgproc.COLOR_BGR2HSV);
    Mat mat3 = new Mat();
    Core.inRange(image1Mat, new Scalar(0, 0, 0), new Scalar(50, 255, 255), mat3);
    Mat mat4 = new Mat();    
    Imgproc.threshold(mat3, mat4, 0, 255, Imgproc.THRESH_BINARY);
    Bitmap threshBitmap = Bitmap.createBitmap(mat4.cols(), mat4.rows(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(mat4, threshBitmap);

图像被转换为​​位图。我检查了像素的颜色,发现黑色像素值为-16777216,白色为-1。为了进一步处理,我需要将这些值更改为原始 java 类型(黑色为 0,白色为 255)。

如何在不改变颜色的情况下操作从 -16777216 到 0 和 -1 到 255 的像素值?有什么办法吗?请帮忙。

4

0 回答 0