aboutsummaryrefslogtreecommitdiff
blob: 48a82994288374da12a456b81b4ccffb4fbc6575 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "dcp_core.h"

void CalcTransmission(IplImage *transmission, IplImage *input, double A[], int radius)
{
	int width = input->width;
	int height = input->height;
	int widthstep = input->widthStep;
	int gwidthstep = transmission->widthStep;
	int nch = input->nChannels;

	double w = 0.95;
	
	IplImage *normalized_input = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);

	for (int k = 0; k < 3; k++)
	{
		for (int i = 0; i < height; i++)
		{
			for (int j = 0; j < width; j++)
			{
				double tmp = *(uchar *)(input->imageData + i * widthstep + j * nch + k);
				tmp = tmp / A[k] * 255.0;

				tmp = tmp > 255 ? 255 : tmp;
				*(uchar *)(normalized_input->imageData + i * widthstep + j * nch + k) = tmp;
			}
		}
	}
	CalcDarkChannel(transmission, normalized_input, radius);

	for (int i = 0; i < height; i++)
	{	
		for (int j = 0; j < width; j++)
		{
			double tran = *(uchar *)(transmission->imageData + i * gwidthstep + j);

			tran = 1 - w * (tran / 255.0);

			tran = tran > 1 ? 1 : tran;
			tran = tran < 0 ? 0 : tran;

			*(uchar *)(transmission->imageData + i * gwidthstep + j) = tran * 255;
		}
	}
	cvReleaseImage(&normalized_input);
}
Powered by cgit v1.2.3 (git 2.41.0)