Ejemplo n.º 1
0
buffer2d< float >
SSIMDiffStrategy::diff( const image & img1, const image & img2 )
{
    size_t w = min( img1.width(), img2.width() );
    size_t h = min( img1.height(), img2.height() );
    float * i0 = new float[ 3 * w * h ];
    float * i1 = new float[ 3 * w * h ];

    for ( size_t y = 0; y < h; ++y ) {
        for ( size_t x = 0; x < w; ++x ) {
            i0[ ( y * w + x ) * 3 + 0 ] = img1( x, y )[ 0 ];
            i0[ ( y * w + x ) * 3 + 1 ] = img1( x, y )[ 1 ];
            i0[ ( y * w + x ) * 3 + 2 ] = img1( x, y )[ 2 ];
            i1[ ( y * w + x ) * 3 + 0 ] = img2( x, y )[ 0 ];
            i1[ ( y * w + x ) * 3 + 1 ] = img2( x, y )[ 1 ];
            i1[ ( y * w + x ) * 3 + 2 ] = img2( x, y )[ 2 ];
        }
    }

    float * weight = new float[ winsize * winsize ];
    gaussian_weight( weight, 0.1, winsize );

    buffer2d< float > result(
        min( img1.width(), img2.width() ) - winsize,
        min( img1.height(), img2.height() ) - winsize
    );

    for ( size_t y = 0; y < result.height(); ++y ) {
        for ( size_t x = 0; x < result.width(); ++x ) {
            result( x, y ) = ( 1 - floatSSIM( i0, i1, result.width() + winsize, result.height() + winsize, 3, 0, x, y, winsize, 0.01*255*0.01*255, 0.03*255*0.03*255, weight ) ) * 0.5;
        }
    }

    delete[] weight;
    delete[] i1;
    delete[] i0;

    /*
    std::vector< float > w = weight_matrix( 0.1, winsize );
    for ( size_t y = 0; y < result.height() - winsize; ++y )
        for ( size_t x = 0; x < result.width() - winsize; ++x )
            result( x, y ) = ( 1 - local_MSSIM(img1, img2, x, y, winsize, w, k1, k2) ) * 0.5;
            */

    return result;
}
Ejemplo n.º 2
0
double	set_up_filter(double t_i, double t_f, int n_pts, double filter_width,
		      double *dt, double *t_start, double *t_stop, int *half_n_f_wts, 
		      int *n_f_wts, double *f_wt) {
	int	i, i1, i2;
	double	time, w_sum, half_width;
	
	*dt = (t_f - t_i) / (n_pts - 1);

	half_width = 0.5 * filter_width;
	*half_n_f_wts = (int)floor (half_width / (*dt));
	*n_f_wts = 2 * (*half_n_f_wts) + 1;
		
	f_wt = (double *) mxCalloc ((size_t)(*n_f_wts), sizeof(double));
	for (i = 0; i <= *half_n_f_wts; i++) {
		time = i * (*dt);
		i1 = *half_n_f_wts - i;
		i2 = *half_n_f_wts + i;
		f_wt[i1] = f_wt[i2] = gaussian_weight(time, half_width);
	}

	*t_start = t_i;		*t_stop = t_f;	/* Initialize start/stop time */

	return(half_width);
}
Ejemplo n.º 3
0
std::vector<long double> bilateral_filter1d(std::vector<long double>&ts, long double& color_range_sigma, int& spacial_range_sigma_factor, std::string& wrap){
	long double ts_min = (long double)std::numeric_limits<int>::max();
	long double ts_max = (long double)std::numeric_limits<int>::min();
	for(int i =0;i<ts.size();++i){
		if(ts_min > ts[i])
			ts_min = ts[i];
		if(ts_max < ts[i])
			ts_max = ts[i];
	}
	std::transform(ts.begin(), ts.end(), ts.begin(), std::bind1st(std::multiplies<double>(),std::abs(1/ts_max)));
	
	long double normalize_color_denom = ts_max-ts_min;
	long double ts_sum = std::accumulate(ts.begin(), ts.end(), 0.0);
	int ts_len = ts.size();
    long double ts_mean =  ts_sum / (long double)ts_len;
    long double ts_stdv = calculate_stdv(ts, ts_mean);
	long double spacial_range_sigma = spacial_range_sigma_factor+1;
	int window_size = (int)std::ceil(2.5*spacial_range_sigma);
	std::vector<long double> bilater_filter1d_data(ts.size(),0.0);

	for(int i=0;i<ts_len;++i){
		long double numerator_sum = 0.0;
		long double denominator_sum = 0.0;
		int window_range = (window_size*2)+1;
		std::vector<long double> w_ts(window_range,0);

		for(int j=0;j<w_ts.size();++j){
			if(wrap == "reflect"){
				int w_index = mod(i+(j-window_size), ts_len);
				w_ts[j] = ts[w_index];
			}else if(wrap == "constant"){
				if((i+(j-window_size) < ts_len) && (i+(j-window_size) > -1))
					w_ts[j] = ts[(i+(j-window_size))];
				else
					w_ts[j] = 0;
			}else if(wrap == "edge"){
				if((i+(j-window_size) < ts_len) && (i+(j-window_size) > -1))
					w_ts[j] = ts[(i+(j-window_size))];
				else if((i+(j-window_size) < 0))
					w_ts[j] = ts[0];
				else if((i+(j-window_size) >= ts_len))
					w_ts[j] = ts[ts_len-1];
			}

			long double ts_c = (ts[i]-ts_mean)/(ts_stdv);
			long double w_ts_c = (w_ts[j]-ts_mean)/(ts_stdv);

			long double fs_d = (std::sqrt(std::pow((w_ts_c- ts_c), 2)+ std::pow((((j-window_size)/(long double)window_size)), 2)));
			long double fs = gaussian_weight(color_range_sigma, fs_d);

			long double gs_d = std::sqrt(std::pow((w_ts[j]-ts[i]), 2) + std::pow((j-window_size), 2));
			long double gs = gaussian_weight(spacial_range_sigma, gs_d);

			denominator_sum += fs*gs;
			numerator_sum += w_ts[j] * fs*gs;
		}

		long double filtered_val = (numerator_sum/denominator_sum);
		bilater_filter1d_data[i] += (filtered_val * std::abs(ts_max));
	}
	return bilater_filter1d_data;
}