aboutsummaryrefslogblamecommitdiff
blob: 0079ef7529e30fb67b1480ee823d057ad6e95b60 (plain) (tree)
1
2
3
4
5
6
7
8
9

                      
                                                                                       
  




                                                  
 


                                                                                            
 
                                    
          
                                                 
                  
                                                        
                          

                                                                                                         
 
                                                             
                                                                                                                      


                          
                                                                 
 


                                                
                  
                                                                                                
 
                                                       

                                                                         
 
                                                                                                  

                  
                                           
  
#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) = cvRound(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 *= 255.0;
			tran = tran > 255 ? 255 : (tran < 0 ? 0 : tran);

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