Difference between revisions of "Example Image Enhancement"

From BoofCV
Jump to navigationJump to search
m
m
Line 10: Line 10:


Example Code:
Example Code:
* [https://github.com/lessthanoptimal/BoofCV/blob/v0.19/examples/src/boofcv/examples/enhance/ExampleImageEnhancement.java ExampleImageEnhancement.java]
* [https://github.com/lessthanoptimal/BoofCV/blob/v0.20/examples/src/boofcv/examples/enhance/ExampleImageEnhancement.java ExampleImageEnhancement.java]


Concepts:
Concepts:
Line 28: Line 28:
  */
  */
public class ExampleImageEnhancement {
public class ExampleImageEnhancement {
static String imagePath = "enhance/dark.jpg";
// static String imagePath = "enhance/dull.jpg";
static ListDisplayPanel mainPanel = new ListDisplayPanel();


/**
/**
Line 34: Line 39:
*/
*/
public static void histogram() {
public static void histogram() {
// BufferedImage buffered = UtilImageIO.loadImage("../data/applet/enhance/dull.jpg");
BufferedImage buffered = UtilImageIO.loadImage(UtilIO.pathExample(imagePath));
BufferedImage buffered = UtilImageIO.loadImage("../data/applet/enhance/dark.jpg");
ImageUInt8 gray = ConvertBufferedImage.convertFrom(buffered,(ImageUInt8)null);
ImageUInt8 gray = ConvertBufferedImage.convertFrom(buffered,(ImageUInt8)null);
ImageUInt8 adjusted = gray.createSameShape();
ImageUInt8 adjusted = gray.createSameShape();
Line 44: Line 48:
ListDisplayPanel panel = new ListDisplayPanel();
ListDisplayPanel panel = new ListDisplayPanel();


ImageStatistics.histogram(gray,histogram);
ImageStatistics.histogram(gray, histogram);
EnhanceImageOps.equalize(histogram, transform);
EnhanceImageOps.equalize(histogram, transform);
EnhanceImageOps.applyTransform(gray, transform, adjusted);
EnhanceImageOps.applyTransform(gray, transform, adjusted);
panel.addImage(ConvertBufferedImage.convertTo(adjusted,null),"Global");
panel.addImage(ConvertBufferedImage.convertTo(adjusted, null), "Global");


EnhanceImageOps.equalizeLocal(gray, 50, adjusted, histogram, transform);
EnhanceImageOps.equalizeLocal(gray, 50, adjusted, histogram, transform);
panel.addImage(ConvertBufferedImage.convertTo(adjusted,null),"Local");
panel.addImage(ConvertBufferedImage.convertTo(adjusted,null),"Local");


panel.addImage(ConvertBufferedImage.convertTo(gray,null),"Original");
panel.addImage(ConvertBufferedImage.convertTo(gray, null), "Original");


panel.setPreferredSize(new Dimension(gray.width,gray.height));
panel.setPreferredSize(new Dimension(gray.width, gray.height));
ShowImages.showWindow(panel,"Histogram",true);
mainPanel.addItem(panel, "Histogram");
}
}


Line 62: Line 66:
*/
*/
public static void sharpen() {
public static void sharpen() {
// BufferedImage buffered = UtilImageIO.loadImage("../data/applet/enhance/dull.jpg");
BufferedImage buffered = UtilImageIO.loadImage(UtilIO.pathExample(imagePath));
BufferedImage buffered = UtilImageIO.loadImage("../data/applet/enhance/dark.jpg");
ImageUInt8 gray = ConvertBufferedImage.convertFrom(buffered,(ImageUInt8)null);
ImageUInt8 gray = ConvertBufferedImage.convertFrom(buffered,(ImageUInt8)null);
ImageUInt8 adjusted = gray.createSameShape();
ImageUInt8 adjusted = gray.createSameShape();
Line 79: Line 82:


panel.setPreferredSize(new Dimension(gray.width,gray.height));
panel.setPreferredSize(new Dimension(gray.width,gray.height));
ShowImages.showWindow(panel,"Sharpen",true);
mainPanel.addItem(panel, "Sharpen");
}
}


Line 86: Line 89:
histogram();
histogram();
sharpen();
sharpen();
ShowImages.showWindow(mainPanel,"Enhancement",true);
}
}


}
}
</syntaxhighlight>
</syntaxhighlight>

Revision as of 08:52, 9 November 2015

Demonstration of different image enhancement operations. If an image is excessively dark or light the visibility of features can be improved by adjusting its histogram. Another technique makes the edges in an image more pronounced by.

Example Code:

Concepts:

  • Visibility

Relevant Applets:

Example Code

/**
 * Demonstration of various ways an image can be "enhanced".  Image enhancement typically refers to making it easier
 * for people to view the image and pick out its details.
 *
 * @author Peter Abeles
 */
public class ExampleImageEnhancement {

	static String imagePath = "enhance/dark.jpg";
//	static String imagePath = "enhance/dull.jpg";

	static ListDisplayPanel mainPanel = new ListDisplayPanel();

	/**
	 * Histogram adjustment algorithms aim to spread out pixel intensity values uniformly across the allowed range.
	 * This if an image is dark, it will have greater contrast and be brighter.
	 */
	public static void histogram() {
		BufferedImage buffered = UtilImageIO.loadImage(UtilIO.pathExample(imagePath));
		ImageUInt8 gray = ConvertBufferedImage.convertFrom(buffered,(ImageUInt8)null);
		ImageUInt8 adjusted = gray.createSameShape();

		int histogram[] = new int[256];
		int transform[] = new int[256];

		ListDisplayPanel panel = new ListDisplayPanel();

		ImageStatistics.histogram(gray, histogram);
		EnhanceImageOps.equalize(histogram, transform);
		EnhanceImageOps.applyTransform(gray, transform, adjusted);
		panel.addImage(ConvertBufferedImage.convertTo(adjusted, null), "Global");

		EnhanceImageOps.equalizeLocal(gray, 50, adjusted, histogram, transform);
		panel.addImage(ConvertBufferedImage.convertTo(adjusted,null),"Local");

		panel.addImage(ConvertBufferedImage.convertTo(gray, null), "Original");

		panel.setPreferredSize(new Dimension(gray.width, gray.height));
		mainPanel.addItem(panel, "Histogram");
	}

	/**
	 * When an image is sharpened the intensity of edges are made more extreme while flat regions remain unchanged.
	 */
	public static void sharpen() {
		BufferedImage buffered = UtilImageIO.loadImage(UtilIO.pathExample(imagePath));
		ImageUInt8 gray = ConvertBufferedImage.convertFrom(buffered,(ImageUInt8)null);
		ImageUInt8 adjusted = gray.createSameShape();


		ListDisplayPanel panel = new ListDisplayPanel();

		EnhanceImageOps.sharpen4(gray, adjusted);
		panel.addImage(ConvertBufferedImage.convertTo(adjusted,null),"Sharpen-4");

		EnhanceImageOps.sharpen8(gray, adjusted);
		panel.addImage(ConvertBufferedImage.convertTo(adjusted,null),"Sharpen-8");

		panel.addImage(ConvertBufferedImage.convertTo(gray,null),"Original");

		panel.setPreferredSize(new Dimension(gray.width,gray.height));
		mainPanel.addItem(panel, "Sharpen");
	}

	public static void main( String args[] )
	{
		histogram();
		sharpen();
		ShowImages.showWindow(mainPanel,"Enhancement",true);
	}

}