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);

}

}

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐