如何使用java opencv对图像进行去噪 [英] How to denoise an image using java opencv
问题描述
在我的情况下,我想删除图像中的所有黑点。在这里我的图像可以表示如下。当我正在使用我的程序时,图像正在平滑程序如何不删除黑点。请帮我删除黑点。请尽快回复我
蒙版和修补:阈值= 70,半径= 20
掩码和修补:阈值= 100,半径= 20
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;
公共类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,grey,Imgproc.COLOR_BGR2GRAY);
Mat mask = new Mat(rgb.size(),CvType.CV_8U);
Imgproc.threshold(灰色,掩码,70,255,Imgproc.THRESH_BINARY_INV);
Mat dn = new Mat(rgb.size(),CvType.CV_8UC3);
Photo.inpaint(rgb,mask,dn,20,Photo.INPAINT_TELEA);
}
}
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
mask and inpainted: threshold = 70, radius = 20
mask and inpainted: threshold = 100, radius = 20
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);
}
}
这篇关于如何使用java opencv对图像进行去噪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!