79
79
histogram->calculate();
81
81
// Memory allocation.
82
map = new double_packet[histogram->getHistogramSegment()];
83
equalize_map = new int_packet[histogram->getHistogramSegment()];
82
map = new double_packet[histogram->getHistogramSegments()];
83
equalize_map = new int_packet[histogram->getHistogramSegments()];
85
85
if( !histogram || !map || !equalize_map )
103
103
memset(&high, 0, sizeof(struct double_packet));
104
104
memset(&low, 0, sizeof(struct double_packet));
106
for(i = 0 ; i < histogram->getHistogramSegment() ; i++)
106
for(i = 0 ; i < histogram->getHistogramSegments() ; i++)
108
108
intensity.red += histogram->getValue(ImageHistogram::RedChannel, i);
109
109
intensity.green += histogram->getValue(ImageHistogram::GreenChannel, i);
115
115
// Stretch the histogram.
118
high = map[histogram->getHistogramSegment()-1];
119
memset(equalize_map, 0, histogram->getHistogramSegment()*sizeof(int_packet));
118
high = map[histogram->getHistogramSegments()-1];
119
memset(equalize_map, 0, histogram->getHistogramSegments()*sizeof(int_packet));
121
for(i = 0 ; i < histogram->getHistogramSegment() ; i++)
121
for(i = 0 ; i < histogram->getHistogramSegments() ; i++)
123
123
if(high.red != low.red)
124
equalize_map[i].red = (uint)(((256*histogram->getHistogramSegment() -1) *
124
equalize_map[i].red = (uint)(((256*histogram->getHistogramSegments() -1) *
125
125
(map[i].red-low.red))/(high.red-low.red));
127
127
if(high.green != low.green)
128
equalize_map[i].green = (uint)(((256*histogram->getHistogramSegment() -1) *
128
equalize_map[i].green = (uint)(((256*histogram->getHistogramSegments() -1) *
129
129
(map[i].green-low.green))/(high.green-low.green));
131
131
if(high.blue != low.blue)
132
equalize_map[i].blue = (uint)(((256*histogram->getHistogramSegment() -1) *
132
equalize_map[i].blue = (uint)(((256*histogram->getHistogramSegments() -1) *
133
133
(map[i].blue-low.blue))/(high.blue-low.blue));
135
135
if(high.alpha != low.alpha)
136
equalize_map[i].alpha = (uint)(((256*histogram->getHistogramSegment() -1) *
136
equalize_map[i].alpha = (uint)(((256*histogram->getHistogramSegments() -1) *
137
137
(map[i].alpha-low.alpha))/(high.alpha-low.alpha));
257
257
memset(&intensity, 0, sizeof(struct double_packet));
259
for(high.red = histogram->getHistogramSegment()-1 ; high.red != 0 ; high.red--)
259
for(high.red = histogram->getHistogramSegments()-1 ; high.red != 0 ; high.red--)
261
261
intensity.red += histogram->getValue(ImageHistogram::RedChannel, (int)high.red);
269
269
threshold_intensity = 0;
270
270
memset(&intensity, 0, sizeof(struct double_packet));
272
for(low.red = 0 ; low.red < histogram->getHistogramSegment()-1 ; low.red++)
272
for(low.red = 0 ; low.red < histogram->getHistogramSegments()-1 ; low.red++)
274
274
intensity.red += histogram->getValue(ImageHistogram::RedChannel, (int)low.red);
280
280
memset(&intensity, 0, sizeof(struct double_packet));
282
for(high.red = histogram->getHistogramSegment()-1 ; high.red != 0 ; high.red--)
282
for(high.red = histogram->getHistogramSegments()-1 ; high.red != 0 ; high.red--)
284
284
intensity.red += histogram->getValue(ImageHistogram::RedChannel, (int)high.red);
293
293
memset(&intensity, 0, sizeof(struct double_packet));
295
for(high.green = histogram->getHistogramSegment()-1 ; high.green != 0 ; high.green--)
295
for(high.green = histogram->getHistogramSegments()-1 ; high.green != 0 ; high.green--)
297
297
intensity.green += histogram->getValue(ImageHistogram::GreenChannel, (int)high.green);
305
305
threshold_intensity = 0;
306
306
memset(&intensity, 0, sizeof(struct double_packet));
308
for(low.green = 0 ; low.green < histogram->getHistogramSegment()-1 ; low.green++)
308
for(low.green = 0 ; low.green < histogram->getHistogramSegments()-1 ; low.green++)
310
310
intensity.green += histogram->getValue(ImageHistogram::GreenChannel, (int)low.green);
316
316
memset(&intensity, 0, sizeof(struct double_packet));
318
for(high.green = histogram->getHistogramSegment()-1 ; high.green != 0 ; high.green--)
318
for(high.green = histogram->getHistogramSegments()-1 ; high.green != 0 ; high.green--)
320
320
intensity.green += histogram->getValue(ImageHistogram::GreenChannel, (int)high.green);
329
329
memset(&intensity, 0, sizeof(struct double_packet));
331
for(high.blue = histogram->getHistogramSegment()-1 ; high.blue != 0 ; high.blue--)
331
for(high.blue = histogram->getHistogramSegments()-1 ; high.blue != 0 ; high.blue--)
333
333
intensity.blue += histogram->getValue(ImageHistogram::BlueChannel, (int)high.blue);
341
341
threshold_intensity = 0;
342
342
memset(&intensity, 0, sizeof(struct double_packet));
344
for(low.blue = 0 ; low.blue < histogram->getHistogramSegment()-1 ; low.blue++)
344
for(low.blue = 0 ; low.blue < histogram->getHistogramSegments()-1 ; low.blue++)
346
346
intensity.blue += histogram->getValue(ImageHistogram::BlueChannel, (int)low.blue);
352
352
memset(&intensity, 0, sizeof(struct double_packet));
354
for(high.blue = histogram->getHistogramSegment()-1 ; high.blue != 0 ; high.blue--)
354
for(high.blue = histogram->getHistogramSegments()-1 ; high.blue != 0 ; high.blue--)
356
356
intensity.blue += histogram->getValue(ImageHistogram::BlueChannel, (int)high.blue);
365
365
memset(&intensity, 0, sizeof(struct double_packet));
367
for(high.alpha = histogram->getHistogramSegment()-1 ; high.alpha != 0 ; high.alpha--)
367
for(high.alpha = histogram->getHistogramSegments()-1 ; high.alpha != 0 ; high.alpha--)
369
369
intensity.alpha += histogram->getValue(ImageHistogram::AlphaChannel, (int)high.alpha);
377
377
threshold_intensity = 0;
378
378
memset(&intensity, 0, sizeof(struct double_packet));
380
for(low.alpha = 0 ; low.alpha < histogram->getHistogramSegment()-1 ; low.alpha++)
380
for(low.alpha = 0 ; low.alpha < histogram->getHistogramSegments()-1 ; low.alpha++)
382
382
intensity.alpha += histogram->getValue(ImageHistogram::AlphaChannel, (int)low.alpha);
388
388
memset(&intensity, 0, sizeof(struct double_packet));
390
for(high.alpha = histogram->getHistogramSegment()-1 ; high.alpha != 0 ; high.alpha--)
390
for(high.alpha = histogram->getHistogramSegments()-1 ; high.alpha != 0 ; high.alpha--)
392
392
intensity.alpha += histogram->getValue(ImageHistogram::AlphaChannel, (int)high.alpha);
401
401
// Stretch the histogram to create the normalized image mapping.
403
memset(normalize_map, 0, histogram->getHistogramSegment()*sizeof(struct int_packet));
403
memset(normalize_map, 0, histogram->getHistogramSegments()*sizeof(struct int_packet));
405
for(i = 0 ; i <= (long)histogram->getHistogramSegment()-1 ; i++)
405
for(i = 0 ; i <= (long)histogram->getHistogramSegments()-1 ; i++)
407
407
if(i < (long) low.red)
408
408
normalize_map[i].red = 0;
409
409
else if (i > (long) high.red)
410
normalize_map[i].red = (256*histogram->getHistogramSegment() -1);
410
normalize_map[i].red = (256*histogram->getHistogramSegments() -1);
411
411
else if (low.red != high.red)
412
normalize_map[i].red = (int)(((256*histogram->getHistogramSegment() -1)*(i-low.red))/(high.red-low.red));
412
normalize_map[i].red = (int)(((256*histogram->getHistogramSegments() -1)*(i-low.red))/(high.red-low.red));
414
414
if(i < (long) low.green)
415
415
normalize_map[i].green = 0;
416
416
else if (i > (long) high.green)
417
normalize_map[i].green = (256*histogram->getHistogramSegment() -1);
417
normalize_map[i].green = (256*histogram->getHistogramSegments() -1);
418
418
else if (low.green != high.green)
419
normalize_map[i].green = (int)(((256*histogram->getHistogramSegment() -1)*(i-low.green))/(high.green-low.green));
419
normalize_map[i].green = (int)(((256*histogram->getHistogramSegments() -1)*(i-low.green))/(high.green-low.green));
421
421
if(i < (long) low.blue)
422
422
normalize_map[i].blue = 0;
423
423
else if (i > (long) high.blue)
424
normalize_map[i].blue = (256*histogram->getHistogramSegment() -1);
424
normalize_map[i].blue = (256*histogram->getHistogramSegments() -1);
425
425
else if (low.blue != high.blue)
426
normalize_map[i].blue = (int)(((256*histogram->getHistogramSegment() -1)*(i-low.blue))/(high.blue-low.blue));
426
normalize_map[i].blue = (int)(((256*histogram->getHistogramSegments() -1)*(i-low.blue))/(high.blue-low.blue));
428
428
if(i < (long) low.alpha)
429
429
normalize_map[i].alpha = 0;
430
430
else if (i > (long) high.alpha)
431
normalize_map[i].alpha = (256*histogram->getHistogramSegment() -1);
431
normalize_map[i].alpha = (256*histogram->getHistogramSegments() -1);
432
432
else if (low.alpha != high.alpha)
433
normalize_map[i].alpha = (int)(((256*histogram->getHistogramSegment() -1)*(i-low.alpha))/(high.alpha-low.alpha));
433
normalize_map[i].alpha = (int)(((256*histogram->getHistogramSegments() -1)*(i-low.alpha))/(high.alpha-low.alpha));
436
436
// Apply result to image.