java图片降噪,如何使用java opencv对图像进行去噪

该博客介绍了一种通过OpenCV库来处理图像中黑点的方法。首先,通过设置阈值来分割出黑点,然后利用inpainting技术进行修复,不影响图像的其他区域。代码示例展示了如何实现这一过程,包括图像读取、灰度转换、阈值处理和inpainting。可以根据不同情况调整阈值和修复半径。
摘要由CSDN通过智能技术生成

In my case I want to remove the all black dots of my image. here my image can be presented as follows. when i was doing using my program the image was smoothing how ever the program doesn't remove the black dots. please help me to remove black dots.please reply me soon

Original Image

the codes are as follows.

public class Denoise {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

try{

System.loadLibrary( Core.NATIVE_LIBRARY_NAME );

Mat source =Imgcodecs.imread("C:\\Users\\My Kindom\\Downloads\\printscreen.JPG",Imgcodecs.CV_LOAD_IMAGE_COLOR);

Mat destination = new Mat(source.rows(),source.cols(),source.type());

destination = source;

Photo.fastNlMeansDenoisingColored(source,destination, 10, 10, 7, 21);

Imgcodecs.imwrite("C:\\Users\\My Kindom\\Downloads\\Denoise.jpg", destination);

}catch(Exception e){}

// TODO code application logic here

}

解决方案

Simply, you can apply a threshold to segment the black dots. Then, using this as a mask, do an inpainting. Inpainting won't affect other regions of the image as denoising. I'm not quite sure what you mean by black dots, so I've applied a simple threshold. You can try with different thresholds, use inRange or whatever to produce the mask. I'm also using an arbitrary inpainting-radius. You may be able to make it better by analyzing contour areas in the mask and then deciding on a radius.

original

uDYixm.jpg

mask and inpainted: threshold = 70, radius = 20

jdxgDm.jpgp7qUAm.jpg

mask and inpainted: threshold = 100, radius = 20

lSGWsm.jpgPUjY6m.jpg

import org.opencv.core.Core;

import org.opencv.core.CvType;

import org.opencv.core.Mat;

import org.opencv.highgui.Highgui;

import org.opencv.imgproc.Imgproc;

import org.opencv.photo.Photo;

public class Dnoise {

public static void doDnoise()

{

System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

Mat rgb = Highgui.imread("ybD8q.jpg");

Mat gray = new Mat(rgb.size(), CvType.CV_8U);

Imgproc.cvtColor(rgb, gray, Imgproc.COLOR_BGR2GRAY);

Mat mask = new Mat(rgb.size(), CvType.CV_8U);

Imgproc.threshold(gray, mask, 70, 255, Imgproc.THRESH_BINARY_INV);

Mat dn = new Mat(rgb.size(), CvType.CV_8UC3);

Photo.inpaint(rgb, mask, dn, 20, Photo.INPAINT_TELEA);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值