Histogram equalization is a technique used to enhance the contrast of image using the histogram of image. The histogram of image represents the frequency of gray levels in the image.The gray levels of image varying from 0 to 255, that is a gray scale image's pixel size is 8 bits(1 byte). So the histogram contains frequency of occurrence of values from 0 to 255.
The aim of histogram equalization is used in digital image processing is to generate an image with equally distributed brightness level over the whole brightness scale.
Histogram equalization can enhance contrast for brightness values close to histogram maxima and decrease contrast near minima.
Step 2: Create image histogram by scan every pixel of image and increment the relevant member of array.
H[grayval(pix)] = H[grayval(pix)]+1.
Step 3: Form a cumulative histogram CH of size 256.
CH[0] = H[0]
CH[i] = CH[i-1] + H[i], i=1,2,3,...255.
Step 4: Set T[i] = Round((255*CH[i])/(NxM))
Step 4: Rescan image and create new image with gray level value,
NewImg[x][y] = T[OldImg[x][y]]
The aim of histogram equalization is used in digital image processing is to generate an image with equally distributed brightness level over the whole brightness scale.
Histogram equalization can enhance contrast for brightness values close to histogram maxima and decrease contrast near minima.
ALGORITHM
Step 1. Image size: NxM, gray level from 0 to 255, create an array H of size 256 and initialise it with 0.Step 2: Create image histogram by scan every pixel of image and increment the relevant member of array.
H[grayval(pix)] = H[grayval(pix)]+1.
Step 3: Form a cumulative histogram CH of size 256.
CH[0] = H[0]
CH[i] = CH[i-1] + H[i], i=1,2,3,...255.
Step 4: Set T[i] = Round((255*CH[i])/(NxM))
Step 4: Rescan image and create new image with gray level value,
NewImg[x][y] = T[OldImg[x][y]]
SCREENSHOTS
![]() |
Histogram Equalisation in Java: 1 |
![]() |
Histogram Equalisation in Java: 2 |
SOURCE CODE
import java.awt.GridLayout;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
/**
*
* @author AJITH KP (http://fb.com/ajithkp560)
* http://www.terminalcoders.blogspot.com
*
*/
public class HistogramEqualization extends JFrame{
HistogramEqualization(String in, String out){
super("..:: Histogram Equalization ::..");
try {
this.setLayout(new GridLayout(1, 2, 10, 10));
JPanel img1 = new JPanel();
JPanel img2 = new JPanel();
File f1 = new File(in);
File f2 = new File(out);
BufferedImage image1 = getGrayscaleImage(ImageIO.read(f1));
img1.add(new JLabel(new ImageIcon(image1)));
BufferedImage image2 = equalize(image1);
ImageIO.write(image2, "png", f2);
img2.add(new JLabel(new ImageIcon(image2)));
this.add(img1);
this.add(img2);
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
BufferedImage equalize(BufferedImage src){
BufferedImage nImg = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
WritableRaster wr = src.getRaster();
WritableRaster er = nImg.getRaster();
int totpix= wr.getWidth()*wr.getHeight();
int[] histogram = new int[256];
for (int x = 1; x < wr.getWidth(); x++) {
for (int y = 1; y < wr.getHeight(); y++) {
histogram[wr.getSample(x, y, 0)]++;
}
}
int[] chistogram = new int[256];
chistogram[0] = histogram[0];
for(int i=1;i<256;i++){
chistogram[i] = chistogram[i-1] + histogram[i];
}
float[] arr = new float[256];
for(int i=0;i<256;i++){
arr[i] = (float)((chistogram[i]*255.0)/(float)totpix);
}
for (int x = 0; x < wr.getWidth(); x++) {
for (int y = 0; y < wr.getHeight(); y++) {
int nVal = (int) arr[wr.getSample(x, y, 0)];
er.setSample(x, y, 0, nVal);
}
}
nImg.setData(er);
return nImg;
}
BufferedImage getGrayscaleImage(BufferedImage src) {
BufferedImage gImg = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
WritableRaster wr = src.getRaster();
WritableRaster gr = gImg.getRaster();
for(int i=0;i<wr.getWidth();i++){
for(int j=0;j<wr.getHeight();j++){
gr.setSample(i, j, 0, wr.getSample(i, j, 0));
}
}
gImg.setData(gr);
return gImg;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("#! TERMINALCODERS ::..\nhttp://www.terminalcoders.blogspot.com");
if(args.length<2){
System.out.println("Usage: java HistogramEqualization <input file name> <output file name>");
}
else{
HistogramEqualization he = new HistogramEqualization(args[0], args[1]);
he.setSize(1024, 500);
he.setVisible(true);
he.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
}
30 comments
Write commentsThanks for Java code.
ReplyThanks... Please share post with your friends... :)
ReplyIs histogram equalization used for increase clarity of image?
ReplyTo create image with equally distributed brightness level... You can see what happened in above images... :)
ReplyIt was worth visiting your blog and I have bookmarked your blog. Hope to visit again
ReplyClick here:
angularjs training in chennai
Click here:
angularjs training in velarchery
I am really happy with your blog because your article is very unique and powerful for new reader.
ReplyClick here:
Selenium Training in Chennai | Selenium Training in Bangalore | Selenium Training in Pune
Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging.
ReplyBlueprism training in tambaram
Blueprism training in annanagar
Blueprism training in velachery
Greetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks a lot.
ReplyAWS Interview Questions And Answers
AWS Online Training | Online AWS Certification Course - Gangboard
AWS Training in Toronto| Amazon Web Services Training in Toronto, Canada
AWS Training in NewYork City | Amazon Web Services Training in Newyork City
AWS Training in London | Amazon Web Services Training in London, UK
AWS Training in Chennai | AWS Training Institute in Chennai Velachery, Tambaram, OMR
AWS Training in Bangalore |Best AWS Training Institute in BTM ,Marathahalli
I really like the dear information you offer in your articles. I’m able to bookmark your site and show the kids check out up here generally. Im fairly positive theyre likely to be informed a great deal of new stuff here than anyone
Replyangularjs online training
apache spark online training
informatica mdm online training
devops online training
aws online training
Thanks a lot for sharing us about this update. Hope you will not get tired on making posts as informative as this.
ReplyMicrosoft Azure online training
Selenium online training
Java online training
Python online training
uipath online training
The article is so informative. This is more helpful. Thanks for sharing.
ReplyLearn best software testing online certification course class in chennai with placement
Best selenium testing online course training in chennai
best online software testing training course institute in chennai with placement
i like your post ethical hacking certification
ReplyVery useful and information content has been shared out here, Thanks for sharing it.sap hr training in bangalore
Replyvery good post...!
Replyinternship in chennai for ece students
internships in chennai for cse students 2019
Inplant training in chennai
internship for eee students
free internship in chennai
eee internship in chennai
internship for ece students in chennai
inplant training in bangalore for cse
inplant training in bangalore
ccna training in chennai
it is wonderful as always and do more and share more
ReplyBEST ANGULAR JS TRAINING IN CHENNAI WITH PLACEMENT
https://www.acte.in/angular-js-training-in-chennai
https://www.acte.in/angular-js-training-in-annanagar
https://www.acte.in/angular-js-training-in-omr
https://www.acte.in/angular-js-training-in-porur
https://www.acte.in/angular-js-training-in-tambaram
https://www.acte.in/angular-js-training-in-velachery
Great post! you are doing an awesome job.
ReplyAngularJS training in chennai | AngularJS training in anna nagar | AngularJS training in omr | AngularJS training in porur | AngularJS training in tambaram | AngularJS training in velachery
This article has great content. Thanks for sharing it across and making it available. It helps in all the way around. Very informative and interesting blog. Appreciate all your efforts.
ReplySelenium Training in Chennai
Selenium Training in Velachery
Selenium Training in Tambaram
Selenium Training in Porur
Selenium Training in Omr
Selenium Training in Annanagar
I really like the dear information you offer in your articles. I’m able to bookmark your site and show the kids check out up here generally. Im fairly positive theyre likely to be informed a great deal of new stuff here than anyone
Replyangularjs online training
IELTS Coaching in chennai
German Classes in Chennai
GRE Coaching Classes in Chennai
TOEFL Coaching in Chennai
Spoken english classes in chennai | Communication training
This article has great content. Thanks for sharing it across and making it available. It helps in all the way around. Very informative and interesting blog. Appreciate all your efforts.
Replysalesforce training in chennai
software testing training in chennai
robotic process automation rpa training in chennai
blockchain training in chennai
devops training in chennai
Mmorpg oyunları
ReplyInstagram takipçi satin al
tiktok jeton hilesi
Tiktok Jeton Hilesi
Sac Ekim Antalya
Takipci Satın Al
instagram takipçi satın al
metin2 pvp serverlar
instagram takipci
SMM PANEL
Replysmm panel
iş ilanları
İnstagram takipçi satın al
Hırdavat
www.beyazesyateknikservisi.com.tr
Servis
jeton hile
Good content. You write beautiful things.
Replyhacklink
mrbahis
sportsbet
taksi
mrbahis
sportsbet
korsan taksi
hacklink
vbet
Good text Write good content success. Thank you
Replybetpark
tipobet
betmatik
slot siteleri
kralbet
mobil ödeme bahis
bonus veren siteler
poker siteleri
amasya
Replyantakya
edirne
elazığ
kayseri
V16L
yurtdışı kargo
Replyresimli magnet
instagram takipçi satın al
yurtdışı kargo
sms onay
dijital kartvizit
dijital kartvizit
https://nobetci-eczane.org/
BPQ
https://saglamproxy.com
Replymetin2 proxy
proxy satın al
knight online proxy
mobil proxy satın al
2İE3
zonguldak
Replyağrı
bakırköy
alanya
aksaray
XN1
web postegro
Replytakipcimx 1000
techy hit tools
0Z5Cİ