public static void histogram ( ) { BufferedImage buffered = UtilImageIO . loadImage ( UtilIO . pathExample ( imagePath ) ) ; GrayU8 gray = ConvertBufferedImage . convertFrom ( buffered , ( GrayU8 ) null ) ; GrayU8 adjusted = gray . createSameShape ( ) ; int histogram [ ] = new int [ 256 ] ; int transform [ ] = new int [ 256 ] ; ListDisplayPanel panel = new ListDisplayPanel ( ) ; ImageStatistics . histogram ( gray , 0 , histogram ) ; EnhanceImageOps . equalize ( histogram , transform ) ; EnhanceImageOps . applyTransform ( gray , transform , adjusted ) ; panel . addImage ( ConvertBufferedImage . convertTo ( adjusted , null ) , "Global" ) ; EnhanceImageOps . equalizeLocal ( gray , 50 , adjusted , 256 , null ) ; 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" ) ; }
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 .