示例#1
0
文件: plotly.py 项目: fschiffers/odak
    def add_plot(self,data_x,data_y=None,label='',mode='lines+markers',row=1,col=1):
        """
        Definition to add data to the plot.

        Parameters
        ----------
        data_x      : ndarray
                      X axis data to be plotted.
        data_y      : ndarray
                      Y axis data to be plotted.
        label       : str
                      Label of the plot.  
        mode        : str
                      Mode for the plot, it can be either lines+markers, lines or markers.
        """
        if type(data_y) == type(None):
           data_y = np.arange(0,data_x.shape[0])
        if np.__name__ == 'cupy':
            data_x = np.asnumpy(data_x)
            data_y = np.asnumpy(data_y)
        self.fig.add_trace(
                           go.Scatter(
                                      x=data_x,
                                      y=data_y,
                                      mode=mode,
                                      name=label,
                                     ),
                           row=row,
                           col=col
                          )
示例#2
0
def modulation_transfer_function(line_x, line_y, px_size):
    """
    Definition to compute modulation transfer function. This definition is based on the work by Peter Burns. For more consult Burns, Peter D. "Slanted-edge MTF for digital camera and scanner analysis." Is and Ts Pics Conference. SOCIETY FOR IMAGING SCIENCE & TECHNOLOGY, 2000.

    Parameters
    ----------
    line_x       : ndarray
                   Slice from an image along X axis. See odak.measurements.roi().
    line_y       : ndarray
                   Slice from an image along Y axis. See odak.measurements.roi().
    px_size      : ndarray
                   Physical angular sizes that each pixels corresponds to on the image plane both for X and Y axes.

    Returns
    ----------
    mtf          : ndarray
                   Calculated modulation transfer function along X and Y axes.
    frq          : ndarray
                   Frequencies of the calculated MTF.
    """
    # 1st derivative of both values: "Line Spread Function",
    der_x = line_spread_function(line_x)
    der_y = line_spread_function(line_y)
    # Fourier transform of the first derivative: "Modulation Transfer Function",
    mtf_x = fourier_transform_1d(der_x)
    mtf_y = fourier_transform_1d(der_y)
    # Arrange the corresponding frequencies,
    n_x = len(der_x)  # length of the signal,
    k_x = np.arange(n_x)
    T_x = n_x * px_size[0]
    frq_x = k_x / T_x
    frq_x = frq_x[np.arange(0, int(n_x / 2))]
    n_y = len(der_y)  # length of the signal,
    k_y = np.arange(n_y)
    T_y = n_y * px_size[1]
    frq_y = k_y / T_y
    frq_y = frq_y[np.arange(0, int(n_y / 2))]
    return [mtf_x, mtf_y], [frq_x, frq_y]
示例#3
0
def fourier_transform_1d(line):
    """
    Definition to take the 1D fourier transform. This is used only for modulation transfer function calculations.

    Parameters
    ----------
    line         : ndarray
                   1D array.

    Returns
    ----------
    result       : ndarray
                   Positive side of the fourier transform of the given line.
    """
    result = np.fft.fft(line)  #/len(der_x)
    result /= np.amax(result)
    result = result[np.arange(0, int(line.shape[0] / 2))]
    return result
示例#4
0
文件: sample.py 项目: fschiffers/odak
def sphere_sample_uniform(no=[10, 10],
                          radius=1.,
                          center=[0., 0., 0.],
                          k=[1, 2]):
    """
    Definition to generate an uniform sample set on the surface of a sphere using polar coordinates.

    Parameters
    ----------
    no          : list
                  Number of samples.
    radius      : float
                  Radius of a sphere.
    center      : list
                  Center of a sphere.
    k           : list
                  Multipliers for gathering samples. If you set k=[1,2] it will draw samples from a perfect sphere.


    Returns
    ----------
    samples     : ndarray
                  Samples generated.

    """
    samples = np.zeros((no[0], no[1], 3))
    row = np.arange(0, no[0])
    psi, teta = np.mgrid[0:no[0], 0:no[1]]
    for psi_id in range(0, no[0]):
        psi[psi_id] = np.roll(row, psi_id, axis=0)
        teta[psi_id] = np.roll(row, -psi_id, axis=0)
    psi = k[0] * np.pi / no[0] * psi
    teta = k[1] * np.pi / no[1] * teta
    samples[:, :, 0] = center[0] + radius * np.sin(psi) * np.cos(teta)
    samples[:, :, 1] = center[1] + radius * np.sin(psi) * np.sin(teta)
    samples[:, :, 2] = center[2] + radius * np.cos(psi)
    samples = samples.reshape((no[0] * no[1], 3))
    return samples