📄 fast_int.c
字号:
/*======================================================================================*//* *//* Main program for the fast interpolation program by Joergen Arendt Jensen *//* Name: fast_int.c *//* First version written February 13, 1999. *//* *//* This is version 1.10 of January 3, 2001 by Joergen Arendt Jensen *//* *//*--------------------------------------------------------------------------------------*//* This module is used for interfacing to the Matlab program. All procedures in the *//* Matlab environment calls the program, that passes parameters on to the different *//* procedures for fast interpolation of 2D and 3D images. *//* *//*--------------------------------------------------------------------------------------*//* Revision history: First version: February 13, 1999 by JAJ *//* *//* Ver. 0.10, 13/ 2-99, JAJ: Initial trials with this version. *//* Ver. 1.00, 20/ 2-99, JAJ: First release version. *//* Ver. 1.10, 3/ 1-01, JAJ: Version for 1024 by 1024 images. *//*======================================================================================*//*-----------------------------------------------------*//* This definition is only used on the HP-UX machine *//*-----------------------------------------------------*/#define NO_BUILT_IN_SUPPORT_FOR_BOOL/* Include usual C type definitions */#include <stdlib.h>#include <stdio.h>#include <math.h>#include <string.h>#include <ctype.h>/* Include typedefinitions for the mex file */#include "mex.h" /*------------------------------------------------------------*/ /* Define various data type, so that they are the same for */ /* different compilers and machines. */ /*------------------------------------------------------------*/#define boolean short /*-----------------------------------------------------------*/ /* Define the global constants used by the program */ /*-----------------------------------------------------------*/#define Nz_max 1024 /* Largest number of pixels in x-direction */#define Nx_max 1024 /* Largest number of pixels in y-direction */#define Ncoef_max 4 /* Largest number of weight coefficients */ /*-------------------------------------------------------------*/ /* Define the global variables used by the program */ /*-------------------------------------------------------------*/float weight_coef[Nz_max * Nx_max * Ncoef_max]; /* Coefficients for the weighting of the image data */int N_values; /* Number of values to calculate in the image */int index_samp_line[Nz_max * Nx_max]; /* Index for the data sample number */int image_index[Nz_max * Nx_max]; /* Index for the image matrix */ boolean table_set_up = 0; /* Whether the tables has been set up */double start_depth; /* Depth for start of image in meters */double image_size; /* Size of image in meters */ double start_of_data; /* Depth for start of data in meters */int N_samples; /* Number of data samples */double delta_r; /* Sampling interval for data in meters */ double theta_start; /* Angle for first line in image */double delta_theta; /* Angle between individual lines */int N_lines; /* Number of acquired lines */double scaling; /* Scaling factor form envelope to image */int Nz, Nx; /* Size of image in pixels */ /*------------------------------------------------------------------------------*/ /* Function for calculating the different weight tables for the interpolation */ /*------------------------------------------------------------------------------*/void make_tables (double start_depth, /* Depth for start of image in meters */ double image_size, /* Size of image in meters */ double start_of_data, /* Depth for start of data in meters */ double delta_r, /* Sampling interval for data in meters */ int N_samples, /* Number of data samples */ double theta_start, /* Angle for first line in image */ double delta_theta, /* Angle between individual lines */ int N_lines, /* Number of acquired lines */ double scaling, /* Scaling factor form envelope to image */ int Nz, /* Size of image in pixels */ int Nx, /* Size of image in pixels */ float *weight_coef, /* The weight table */ int *index_samp_line,/* Index for the data sample number */ int *image_index, /* Index for the image matrix */ int *N_values) /* Number of values to calculate in the image */ {int i,j; /* Integer loop counters */ double z,z2,x; /* Image coordinates in meters */ double dz,dx; /* Increments in image coordinates in meters */ double radius; /* Radial distance */ double theta; /* Angle in degrees */ double samp; /* Sample number for interpolation */ double line; /* Line number for interpolation */ int index_samp; /* Index for the data sample number */ int index_line; /* Index for the data line number */ double samp_val; /* Sub-sample fraction for interpolation */ double line_val; /* Sub-line fraction for interpolation */ boolean make_pixel; /* Whether the values is used in the image */ int ij_index; /* Index into array */ int ij_index_coef; /* Index into coefficient array */ dz = image_size/Nz; dx = image_size/Nx; z = start_depth; ij_index = 0; ij_index_coef = 0; for (i=0; i<Nz; i++) { x = -image_size/2; z2 = z*z; for (j=0; j<Nx; j++) { /* Find which samples to select from the envelope array */ radius = sqrt(z2+x*x); theta = atan2 (x,z); samp = (radius - start_of_data)/delta_r; line = (theta - theta_start)/delta_theta; index_samp = floor(samp); index_line = floor(line); /* Test whether the samples are outside the array */ make_pixel = (index_samp >= 0) && (index_samp+1 < N_samples) && (index_line >= 0) && (index_line+1 < N_lines); if (make_pixel) { samp_val = samp - index_samp; line_val = line - index_line; /* Calculate the coefficients if necessary */ weight_coef[ij_index_coef ] = (1-samp_val)*(1-line_val)*scaling;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -