Difference between revisions of "Example Image Blur"

From BoofCV
Jump to navigationJump to search
m
m
Line 1: Line 1:
<center>
<center>
<gallery heights=250 widths=320 perrow=4 >
<gallery heights=250 widths=250 perrow=4 >
File:example_disparity_smoothing_raw.jpg|Before any post processing. Notice all the noise?
File:Kodim17_face_orig.jpg|Input image
File:example_disparity_smoothing_speckle.jpg|After speckle has been removed.
File:Kodim17_face_gaussian.jpg|Gaussian Filter
File:Kodim17_face_mean.jpg|Mean Filter
File:Kodim17_face_median.jpg|Median Filter
</gallery>
</gallery>
</center>
</center>
Line 9: Line 11:


Example Code:
Example Code:
* [https://github.com/lessthanoptimal/BoofCV/blob/v0.37/examples/src/main/java/boofcv/examples/imageprocessing/ExampleImageBlur.java ExampleImageBlur.java]
* [https://github.com/lessthanoptimal/BoofCV/blob/v0.33/examples/src/main/java/boofcv/examples/imageprocessing/ExampleImageBlur.java ExampleImageBlur.java]


Concepts:
Concepts:
* Stereo Disparity
* Image Processing
* Filtering
* Filtering


Related Examples:
Related Examples:
* [[Example_Stereo_Disparity| Stereo Disparity]]
* [[Example_Image_Filter| Image Filter]]
* [[Example_Convolution| Convolutions]]


= Example Code =
= Example Code =
Line 29: Line 32:
  */
  */
public class ExampleImageBlur {
public class ExampleImageBlur {
public static void main( String[] args ) {
 
public static void main(String[] args) {
ListDisplayPanel panel = new ListDisplayPanel();
ListDisplayPanel panel = new ListDisplayPanel();
BufferedImage buffered = UtilImageIO.loadImage(UtilIO.pathExample("standard/kodim17.jpg"));
BufferedImage buffered = UtilImageIO.loadImage(UtilIO.pathExample("standard/kodim17.jpg"));


panel.addImage(buffered, "Original");
panel.addImage(buffered,"Original");


Planar<GrayU8> input = ConvertBufferedImage.convertFrom(buffered, true, ImageType.pl(3, GrayU8.class));
Planar<GrayU8> input = ConvertBufferedImage.convertFrom(buffered, true, ImageType.pl(3, GrayU8.class));
Line 42: Line 46:


// Apply gaussian blur using a procedural interface
// Apply gaussian blur using a procedural interface
GBlurImageOps.gaussian(input, blurred, -1, radius, null);
GBlurImageOps.gaussian(input,blurred,-1,radius,null);
panel.addImage(ConvertBufferedImage.convertTo(blurred, null, true), "Gaussian");
panel.addImage(ConvertBufferedImage.convertTo(blurred, null, true),"Gaussian");


// Apply a mean filter using an object oriented interface.  This has the advantage of automatically
// Apply a mean filter using an object oriented interface.  This has the advantage of automatically
// recycling memory used in intermediate steps
// recycling memory used in intermediate steps
BlurFilter<Planar<GrayU8>> filterMean = FactoryBlurFilter.mean(input.getImageType(), radius);
BlurFilter<Planar<GrayU8>> filterMean = FactoryBlurFilter.mean(input.getImageType(),radius);
filterMean.process(input, blurred);
filterMean.process(input, blurred);
panel.addImage(ConvertBufferedImage.convertTo(blurred, null, true), "Mean");
panel.addImage(ConvertBufferedImage.convertTo(blurred, null, true),"Mean");


// Apply a median filter using image type specific procedural interface.  Won't work if the type
// Apply a median filter using image type specific procedural interface.  Won't work if the type
// isn't known at compile time
// isn't known at compile time
BlurImageOps.median(input, blurred, radius, radius, null);
BlurImageOps.median(input,blurred,radius, null);
panel.addImage(ConvertBufferedImage.convertTo(blurred, null, true), "Median");
panel.addImage(ConvertBufferedImage.convertTo(blurred, null, true),"Median");


ShowImages.showWindow(panel, "Image Blur Examples", true);
ShowImages.showWindow(panel,"Image Blur Examples",true);
}
}
}
}
</syntaxhighlight>
</syntaxhighlight>

Revision as of 14:07, 22 December 2020

Applying different types of image blur is a common way to "remove" noise from images and make later steps more effective. This example shows you how to apply different image blur operators using different interfaces.

Example Code:

Concepts:

  • Image Processing
  • Filtering

Related Examples:

Example Code

/**
 * This example shows you can can apply different standard image blur filters to an input image using different
 * interface.  For repeat calls using the filter interface has some advantages, but the procedural can be
 * simple to code up.
 *
 * @author Peter Abeles
 */
public class ExampleImageBlur {

	public static void main(String[] args) {
		ListDisplayPanel panel = new ListDisplayPanel();
		BufferedImage buffered = UtilImageIO.loadImage(UtilIO.pathExample("standard/kodim17.jpg"));

		panel.addImage(buffered,"Original");

		Planar<GrayU8> input = ConvertBufferedImage.convertFrom(buffered, true, ImageType.pl(3, GrayU8.class));
		Planar<GrayU8> blurred = input.createSameShape();

		// size of the blur kernel. square region with a width of radius*2 + 1
		int radius = 8;

		// Apply gaussian blur using a procedural interface
		GBlurImageOps.gaussian(input,blurred,-1,radius,null);
		panel.addImage(ConvertBufferedImage.convertTo(blurred, null, true),"Gaussian");

		// Apply a mean filter using an object oriented interface.  This has the advantage of automatically
		// recycling memory used in intermediate steps
		BlurFilter<Planar<GrayU8>> filterMean = FactoryBlurFilter.mean(input.getImageType(),radius);
		filterMean.process(input, blurred);
		panel.addImage(ConvertBufferedImage.convertTo(blurred, null, true),"Mean");

		// Apply a median filter using image type specific procedural interface.  Won't work if the type
		// isn't known at compile time
		BlurImageOps.median(input,blurred,radius, null);
		panel.addImage(ConvertBufferedImage.convertTo(blurred, null, true),"Median");

		ShowImages.showWindow(panel,"Image Blur Examples",true);
	}
}