fix mathematical mistake in normalize
This commit is contained in:
		
							parent
							
								
									58bf764af9
								
							
						
					
					
						commit
						544455bea8
					
				
					 1 changed files with 35 additions and 19 deletions
				
			
		| 
						 | 
				
			
			@ -21,28 +21,44 @@
 | 
			
		|||
#include <opencv2/core/ocl.hpp>
 | 
			
		||||
#include <opencv2/imgproc.hpp>
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
 | 
			
		||||
inline bool normalize(cv::Mat& image, const cv::Mat& referance)
 | 
			
		||||
{
 | 
			
		||||
	cv::Mat labReferance;
 | 
			
		||||
	cv::cvtColor(referance, labReferance, cv::COLOR_BGR2Lab);
 | 
			
		||||
	std::vector<cv::Mat> labPlanesRef(3);
 | 
			
		||||
	cv::split(labReferance, labPlanesRef);
 | 
			
		||||
	assert(image.size() == referance.size());
 | 
			
		||||
	assert(image.type() == referance.type());
 | 
			
		||||
	assert(image.type() == CV_8UC3 || image.type() == CV_32FC1);
 | 
			
		||||
	
 | 
			
		||||
	if(image.type() == CV_8UC3)
 | 
			
		||||
	{
 | 
			
		||||
		cv::Mat labReferance;
 | 
			
		||||
		cv::cvtColor(referance, labReferance, cv::COLOR_BGR2Lab);
 | 
			
		||||
		std::vector<cv::Mat> labPlanesRef(3);
 | 
			
		||||
		cv::split(labReferance, labPlanesRef);
 | 
			
		||||
 | 
			
		||||
	cv::Scalar mean = cv::mean(labPlanesRef[0]);
 | 
			
		||||
	labPlanesRef[0].convertTo(labPlanesRef[0], CV_16SC1);
 | 
			
		||||
	
 | 
			
		||||
	labPlanesRef[0] = labPlanesRef[0] - cv::Scalar(mean);
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	cv::Mat labImage;
 | 
			
		||||
	cv::cvtColor(image, labImage, cv::COLOR_BGR2Lab);
 | 
			
		||||
	
 | 
			
		||||
	std::vector<cv::Mat> labPlanes(3);
 | 
			
		||||
	cv::split(labImage, labPlanes);
 | 
			
		||||
	
 | 
			
		||||
	cv::subtract(labPlanes[0], labPlanesRef[0], labPlanes[0], cv::noArray(), CV_8UC1);
 | 
			
		||||
	cv::merge(labPlanes, labImage);
 | 
			
		||||
	cv::cvtColor(labImage, image,  cv::COLOR_Lab2BGR);
 | 
			
		||||
		cv::Scalar mean = cv::mean(labPlanesRef[0]);
 | 
			
		||||
		labPlanesRef[0].convertTo(labPlanesRef[0], CV_16SC1);
 | 
			
		||||
		
 | 
			
		||||
		labPlanesRef[0] = mean/labPlanesRef[0];
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
		cv::Mat labImage;
 | 
			
		||||
		cv::cvtColor(image, labImage, cv::COLOR_BGR2Lab);
 | 
			
		||||
		
 | 
			
		||||
		std::vector<cv::Mat> labPlanes(3);
 | 
			
		||||
		cv::split(labImage, labPlanes);
 | 
			
		||||
		
 | 
			
		||||
		labPlanes[0] = labPlanes[0].mul(labPlanesRef[0]);
 | 
			
		||||
		cv::merge(labPlanes, labImage);
 | 
			
		||||
		cv::cvtColor(labImage, image,  cv::COLOR_Lab2BGR);
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		cv::Scalar mean = cv::mean(referance);
 | 
			
		||||
		cv::Mat referanceNorm;
 | 
			
		||||
		referance.copyTo(referanceNorm);
 | 
			
		||||
		referanceNorm = mean/referanceNorm;
 | 
			
		||||
		image = image*referanceNorm;
 | 
			
		||||
	}
 | 
			
		||||
	return true;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue