Exemplo n.º 1
0
TEST(Projection, Forward)
{
	cudaDeviceReset();

	//Case 1:
	{
		int3 dimsvolume = {8, 8, 8};
		int3 dimsimage = {8, 8, 1};
		tfloat3 angles = tfloat3(PI / 2.0f, PI / 2.0f, 0.0f);
		tfloat2 shifts = tfloat2(0, 0);
		tfloat weight = (tfloat)1;
		tfloat* d_inputvolume = (tfloat*)CudaMallocFromBinaryFile("Data\\Projection\\Input_Forward_1.bin");
		tfloat* d_volumepsf = CudaMallocValueFilled(ElementsFFT(dimsvolume), (tfloat)1);
		tfloat* d_proj = (tfloat*)CudaMallocValueFilled(Elements(dimsimage), (tfloat)0);
		tfloat* desired_output = (tfloat*)MallocFromBinaryFile("Data\\Projection\\Output_Forward_1.bin");
		tfloat* d_projpsf = CudaMallocValueFilled(ElementsFFT(dimsimage), (tfloat)0);
		
		d_ProjForward(d_inputvolume, d_volumepsf, dimsvolume, d_proj, d_projpsf, &angles, &shifts, T_INTERP_CUBIC, 1);

		tfloat* h_output = (tfloat*)MallocFromDeviceArray(d_proj, Elements(dimsimage) * sizeof(tfloat));
	
		double MeanAbsolute = GetMeanAbsoluteError((tfloat*)desired_output, (tfloat*)h_output, Elements(dimsimage));
		ASSERT_LE(MeanAbsolute, 1e-5);

		cudaFree(d_inputvolume);
		cudaFree(d_proj);
		free(desired_output);
		free(h_output);
	}

	cudaDeviceReset();
}
Exemplo n.º 2
0
TEST(Correlation, Peak)
{
	cudaDeviceReset();

	//Case 1:
	{
		int3 dims = {8, 8, 1};
		tfloat* d_input = (tfloat*)CudaMallocFromBinaryFile("Data\\Correlation\\Input_Peak_1.bin");
		tfloat3* desired_output = (tfloat3*)MallocFromBinaryFile("Data\\Correlation\\Output_Peak_1.bin");
		tfloat3* d_positions;
		cudaMalloc((void**)&d_positions, sizeof(tfloat3));
		tfloat* d_values;
		cudaMalloc((void**)&d_values, sizeof(tfloat));

		d_Peak(d_input, d_positions, d_values, dims, T_PEAK_MODE::T_PEAK_INTEGER);

		tfloat3* h_positions = (tfloat3*)MallocFromDeviceArray(d_positions, sizeof(tfloat3));
		tfloat* h_values = (tfloat*)MallocFromDeviceArray(d_values, sizeof(tfloat));
	
		double MeanRelative = GetMeanRelativeError((tfloat*)desired_output, (tfloat*)h_positions, 3);
		ASSERT_LE(MeanRelative, 1e-5);

		cudaFree(d_input);
		cudaFree(d_positions);
		cudaFree(d_values);
		free(desired_output);
		free(h_positions);
		free(h_values);
	}

	//Case 2:
	{
		int3 dims = {20, 20, 1};
		tfloat* d_input = (tfloat*)CudaMallocFromBinaryFile("Data\\Correlation\\Input_Peak_2.bin");
		tfloat3* desired_output = (tfloat3*)MallocFromBinaryFile("Data\\Correlation\\Output_Peak_2.bin");
		tfloat3* d_positions;
		cudaMalloc((void**)&d_positions, sizeof(tfloat3));
		tfloat* d_values;
		cudaMalloc((void**)&d_values, sizeof(tfloat));

		d_Peak(d_input, d_positions, d_values, dims, T_PEAK_MODE::T_PEAK_SUBCOARSE);

		tfloat3* h_positions = (tfloat3*)MallocFromDeviceArray(d_positions, sizeof(tfloat3));
		tfloat* h_values = (tfloat*)MallocFromDeviceArray(d_values, sizeof(tfloat));
	
		double MeanRelative = GetMeanAbsoluteError((tfloat*)desired_output, (tfloat*)h_positions, DimensionCount(dims));
		ASSERT_LE(MeanRelative, 0.05);

		cudaFree(d_input);
		cudaFree(d_positions);
		cudaFree(d_values);
		free(desired_output);
		free(h_positions);
		free(h_values);
	}

	//Case 3:
	{
		int3 dims = {20, 20, 1};
		tfloat* d_input = (tfloat*)CudaMallocFromBinaryFile("Data\\Correlation\\Input_Peak_2.bin");
		tfloat3* desired_output = (tfloat3*)MallocFromBinaryFile("Data\\Correlation\\Output_Peak_2.bin");
		tfloat3* d_positions;
		cudaMalloc((void**)&d_positions, sizeof(tfloat3));
		tfloat* d_values;
		cudaMalloc((void**)&d_values, sizeof(tfloat));

		d_Peak(d_input, d_positions, d_values, dims, T_PEAK_MODE::T_PEAK_SUBFINE);

		tfloat3* h_positions = (tfloat3*)MallocFromDeviceArray(d_positions, sizeof(tfloat3));
		tfloat* h_values = (tfloat*)MallocFromDeviceArray(d_values, sizeof(tfloat));
	
		double MeanRelative = GetMeanAbsoluteError((tfloat*)desired_output, (tfloat*)h_positions, DimensionCount(dims));
		ASSERT_LE(MeanRelative, 0.02);

		cudaFree(d_input);
		cudaFree(d_positions);
		cudaFree(d_values);
		free(desired_output);
		free(h_positions);
		free(h_values);
	}

	cudaDeviceReset();
}
Exemplo n.º 3
0
MagickExport MagickBooleanType GetImageChannelDistortion(Image *image,
  const Image *reconstruct_image,const ChannelType channel,
  const MetricType metric,double *distortion,ExceptionInfo *exception)
{
  assert(image != (Image *) NULL);
  assert(image->signature == MagickSignature);
  if (image->debug != MagickFalse)
    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
  assert(reconstruct_image != (const Image *) NULL);
  assert(reconstruct_image->signature == MagickSignature);
  assert(distortion != (double *) NULL);
  *distortion=0.0;
  if (image->debug != MagickFalse)
    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
  if ((reconstruct_image->columns != image->columns) ||
      (reconstruct_image->rows != image->rows))
    ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
  /*
    Get image distortion.
  */
  switch (metric)
  {
    case AbsoluteErrorMetric:
    {
      *distortion=(double) GetAbsoluteError(image,reconstruct_image,exception);
      break;
    }
    case MeanAbsoluteErrorMetric:
    {
      *distortion=(double) GetMeanAbsoluteError(image,reconstruct_image,channel,
        exception);
      break;
    }
    case MeanErrorPerPixelMetric:
    {
      *distortion=(double) GetMeanErrorPerPixel(image,reconstruct_image,channel,
        exception);
      break;
    }
    case MeanSquaredErrorMetric:
    {
      *distortion=(double) GetMeanSquaredError(image,reconstruct_image,channel,
        exception);
      break;
    }
    case PeakAbsoluteErrorMetric:
    default:
    {
      *distortion=(double) GetPeakAbsoluteError(image,reconstruct_image,channel,
        exception);
      break;
    }
    case PeakSignalToNoiseRatioMetric:
    {
      *distortion=(double) GetPeakSignalToNoiseRatio(image,reconstruct_image,
        channel,exception);
      break;
    }
    case RootMeanSquaredErrorMetric:
    {
      *distortion=(double) GetRootMeanSquaredError(image,reconstruct_image,
        channel,exception);
      break;
    }
  }
  return(MagickTrue);
}