dG1_theta_conv2.cpp 2.09 KB
#include <stim/image/image.h>
#include <cmath>
#include <stim/visualization/colormap.h>
#include <stim/image/image_contour_detection.h>

#define PI 3.1415926
#define SIGMA_N 3

void array_multiply(float* lhs, float rhs, unsigned int N);
void array_add(float* ptr1, float* ptr2, float* sum, unsigned int N);
void array_abs(float* img, unsigned int N);

/// This function evaluates the theta-dependent odd symmetric gaussian derivative gradient of an one-channel image

/// @param img is the one-channel image
/// @param r is an array of radii for different scaled discs(filters)
/// @param sigma_n is the number of standard deviations used to define the sigma
/// @param theta is angle used for computing the gradient

stim::image<float> dG1_theta_conv2(stim::image<float> image, int sigma, float theta){

	float theta_r = (theta * PI)/180; //change angle unit from degree to rad

	unsigned int w = image.width();    // get the width of picture
	unsigned int h = image.height();   // get the height of picture

	int r = SIGMA_N * sigma;  
	unsigned N = w * h;				   // get the number of pixels of picture

	int winsize = 2 * SIGMA_N * sigma + 1;           // set the winsdow size of filter

	stim::image<float> I(w, h, 1, 2);       // allocate space for return image of dG1_conv2
	stim::image<float> Ix(w, h);			// allocate space for Ix
	stim::image<float> Iy(w, h);			// allocate space for Iy
	stim::image<float> dG1_theta(w, h);     // allocate space for Pb

	I = dG1_conv2(image, sigma);  // calculate the Ix, Iy
	Ix = I.channel(0);
	Iy = I.channel(1);

	array_multiply(Ix.data(), cos(theta_r), N);								//Ix = Ix*cos(theta_r)
	array_multiply(Iy.data(), sin(theta_r), N);								//Iy = Iy*sin(theta_r)
	array_add(Ix.data(), Iy.data(), dG1_theta.data(), N);				//dG1_theta = Ix + Iy;
	array_abs(dG1_theta.data(), N);		

	//stim::cpu2image(I.channel(0).data(), "data_output/dG1_theta_x_0919.bmp", w, h, stim::cmBrewer); 
	//stim::cpu2image(I.channel(1).data(), "data_output/dG1_theta_y_0919.bmp", w, h, stim::cmBrewer); 
	//stim::cpu2image(dG1_theta.data(), "data_output/dG1_theta_0919.bmp", w, h, stim::cmBrewer); 

	return dG1_theta;

}