示例#1
0
def save(file_root,
         file_name,
         file_type=dic.FILE_TYPES['png'],
         image=dic.IMAGE_TYPES['Color']):
    """
    Save image.|
    -----------
    The function overwrites an existing file.
    -----------------------------------------------------------------------

    Parameters
    ----------
    file_root : QString
        Destination file root.
    file_name : QString
        Destination file name.
    file_type : QString, optional
        Destination file type. The default is dic.FILE_TYPES['png'].
    image : int, optional
        Index of image to save. The default is dic.IMAGE_TYPES['Color'].

    Returns
    -------
    None.

    """

    if not os.path.exists(file_root):
        os.makedirs(file_root)
    err_code = ax.LMK.iSaveImage(image, file_root + file_name + file_type)
    ax.error_code(err_code)  # Check for error
示例#2
0
def create_rect_image_size(
        image=dic.IMAGE_TYPES['Color'],
        region_id=dic.REGION_TYPES['Rectangle']['identifier'],
        region_points=dic.REGION_TYPES['Rectangle']['points']):
    """
    Create a rectangular region the size of the whole image.|
    --------------------------------------------------------
    Parameters:
        :LMK:
            | Dispatch('lmk4.LMKAxServer')
        :image: int (default: IMAGE_TYPES['Color'])
            | Index of region list (same as image index)
            | Im is usually defined as 'Image', but we needed to call in Image() here
        :region_id: int (default: REGION_TYPES['Rectangle']['identifier'])
            | Type of region from REGION_TYPES{}
        :NumPoints: int (default: REGION_TYPES['Rectangle']['points'])
            | Number of points from REGION_TYPES{}
    Returns:
        :region_x_points: QStringList
            | List of x-points
        :region_y_points: QStringList
            | List of y-points
    """
    [image_first_line, image_last_line, image_first_col, image_last_col,
     _] = im.get_size()
    x_coords = [image_first_col, image_last_col]
    y_coords = [image_first_line, image_last_line]
    [err_code, region_x_points, region_y_points] \
        = ax.LMK.iCreateRegion(image, region_id, region_points, x_coords, y_coords)
    ax.error_code(err_code)  # Check for error

    return region_x_points, region_y_points
示例#3
0
def load(file_root,
         file_name,
         file_type=dic.FILE_TYPES['pcf'],
         image=dic.IMAGE_TYPES['Color']):
    """
    Load image from .pcf.|
    ---------------------
    Loads a saved image from .pcf. Of course, the image needs to be saved
    first.
    -----------------------------------------------------------------------

    Parameters
    ----------
    file_root : QString
        Source file root.
    file_name : QString
        Source file name.
    file_type : QString, optional
        Source file type.
        .pus = Camera Image
        .pf = Luminance Image
        .pcf = Color Image
        The default is dic.FILE_TYPES['pcf'].
    image : int, optional
        Index of image to Load to. The default is dic.IMAGE_TYPES['Color'].

    Returns
    -------
    None.

    """

    err_code = ax.LMK.iLoadImage(image, file_root + file_name + file_type)
    ax.error_code(err_code)  # Check for error
示例#4
0
def create(image=dic.IMAGE_TYPES['Color'],
           region='Ellipse',
           x_coords=[1226, 500, 500],
           y_coords=[1026, 500, 500]):
    """
    Create a region.|
    ----------------

    Parameters
    ----------
    image : TYPE, optional
        DESCRIPTION. The default is dic.IMAGE_TYPES['Color'].
    region : TYPE, optional
        DESCRIPTION. The default is 'Ellipse'.
    x_coords : TYPE, optional
        DESCRIPTION. The default is [1226, 500, 500].
    y_coords : TYPE, optional
        DESCRIPTION. The default is [1026, 500, 500].

    Returns
    -------
    region_x_points : TYPE
        DESCRIPTION.
    region_y_points : TYPE
        DESCRIPTION.

    """
    [err_code, region_x_points, region_y_points] \
        = ax.LMK.iCreateRegion(image, dic.REGION_TYPES[region]['identifier'],
                               dic.REGION_TYPES[region]['points'], x_coords,
                               y_coords)
    ax.error_code(err_code)  # Check for error

    return region_x_points, region_y_points
示例#5
0
def create(image=0, name='Evaluation[1]'):
    """
    Creates an image.|
    ---------------------------
    The image gets the size of the previous image (luminance image or previous
    evalutation image.)
    ---------------------------------------------------------------------------

    %timeit:
        41.4 ms ± 41.5 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

    Parameters
    ----------
    LMK :
        Dispatch('lmk4.LMKAxServer')
    image : int, optional
        0=Grey image, 1=Color image. The default is 0.
    name : QString, optional
        Wished image  name. The default is 'Evaluation[1]'.

    Returns
    -------
    index : int
        Index of the image created

    """

    err_code, index = ax.LMK.iImageCreate(image, name)
    ax.error_code(err_code)

    return index
示例#6
0
def get_target_properties():
    """
    Get properties of current target.|
    ---------------------------------
    The size of the target image is fixed.
    -----------------------------------------------------------------------
    Parameters:
        :LMK:
            | Dispatch('lmk4.LMKAxServer')
    Returns:
        :target_type: int
            | 1 = Monochrome image
            | 2 = Color image
            | 3 = Display
            |       in this case the type (monochrome or color)
            |       is chosen automatically
        :target_height: int
            | Height in millimeters
        :target_width: int
            | Width in millimeters
        :target_lines: int
            | Number of image lines
        :target_columns: int
            | Number of image columns
    """
    err_code, target_type, target_height, \
        target_width, target_lines, \
            target_columns = ax.LMK.iTIG_GetTargetProperties()
    ax.error_code(err_code)  # Check for error

    return target_type, target_height, target_width, target_lines, target_columns
示例#7
0
def set_value_unit(image=dic.IMAGE_TYPES['Color'],
                   x_value='x',
                   x_unit='pix',
                   y_value='y',
                   y_unit='pix',
                   unit_area='pix^2'):
    """
    Set the values and units of the axis.|
    -------------------------------------
    Parameters:
        :LMK:
            | Dispatch('lmk4.LMKAxServer')
        :image: int (default: IMAGE_TYPES['Color'])
            | Index of image
        :x_value: QString (default: 'x')
            | Value of X axis
        :x_unit: QString (default: 'pix')
            | Unit of X axis
        :y_value: QString (default: 'y')
            | Value of Y axis
        :y_unit: QString (default: 'pix')
            | Unit of Y axis
        :unit_area: QString (default: 'pix^2')
            | Unit of area
    """
    err_code = ax.LMK.iCoordSystemSetValueUnit(image, x_value, x_unit, y_value,
                                               y_unit, unit_area)
    ax.error_code(err_code)  # Check for error
示例#8
0
def multi_pic(calibration_data_root,
              camera_no,
              autoscan=True,
              exposure_time=0.1,
              pic_count=1):
    """
    MultiPic capture algorithm.|
    ---------------------------
    Parameters:
        :LMK:
            | Dispatch('lmk4.LMKAxServer')
        :exposure_time: float (default: 0.1)
            | Exposure time to use
        :pic_count: int (default: 1)
            | Number of camera images
    """

    if autoscan is True:
        _, filter_wheel_names = cam.get_filter_wheels(calibration_data_root,
                                                      camera_no)
        exposure_times = cam.color_autoscan_time(
            filter_wheel_names)  # [REQUIRED if wanting best exposure times]
        err_code = ax.LMK.iMultiPic2(max(exposure_times.items(), \
                                      key=operator.itemgetter(1))[1], pic_count)
    else:
        err_code = ax.LMK.iMultiPic2(exposure_time, pic_count)
    ax.error_code(err_code)  # Check for error
示例#9
0
def get_program_info():
    """

    Get some information about program version and camera current used.|
    -------------------------------------------------------------------

    %timeit:
        144 µs ± 5.82 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)

    Parameters
    ----------
    LMK :
        Dispatch('lmk4.LMKAxServer')

    Returns
    -------
    program_type : QString
        Type of program version
    program_version : QString
        Number of program version
    camera_type : QString
        Type of camera
    camera_no : QString
        Number of camera
    lens_no : QString
        Number of lens

    """

    err_code, program_type, program_version, camera_type, camera_no, lens_no = \
        ax.LMK.iGetProgramInfo()
    ax.error_code(err_code)  # Check for error

    return program_type, program_version, camera_type, camera_no, lens_no
示例#10
0
def get_value_unit(image=dic.IMAGE_TYPES['Color']):
    """
    Get the values and units of the axis.|
    -------------------------------------
    Parameters:
        :LMK:
            | Dispatch('lmk4.LMKAxServer')
        :Image: int (default: IMAGE_TYPES['Color'])
            | Index of image
    Returns:
        :x_value: QString
            | Value of X axis
        :x_unit: QString
            | Unit of X axis
        :y_value: QString
            | Value of Y axis
        :y_unit: QString
            | Unit of Y axis
        :unit_area: QString
            | Unit of area
    """
    [err_code, x_value, x_unit, y_value, y_unit,
     unit_area] = ax.LMK.iCoordSystemGetValueUnit(image)
    ax.error_code(err_code)  # Check for error

    return x_value, x_unit, y_value, y_unit, unit_area
示例#11
0
def create_statistic(statistic_type=dic.STATISTIC_TYPES['standardColor'],
                     image=dic.IMAGE_TYPES['Color'],
                     region=0,
                     num_param=1,
                     param_list=[1]):
    """
    Create a new statistic.|
    -----------------------
    Parameters:
        :lmk:
            | Dispatch('lmk4.LMKAxServer')
        :statistic_type: int (default: STATISTIC_TYPES['standardColor'])
            | Index of statistic type
        :image: int (default: Image = IMAGE_TYPES['Color'])
            | Image
        :region: int (default: 0)
            | Index of region in this image
        :num_param: int (default: 1)
            | Number of parameters for this statistic
        :param_list: QStringList
    """
    [err_code,
     statistic] = ax.LMK.iCreateStatistic(statistic_type, image, region,
                                          num_param, param_list)
    ax.error_code(err_code)  # Check for error

    return statistic
示例#12
0
def open_camera(calibration_data_root, camera_no, lens_no):
    """
    Set new camera calibration data.|
    --------------------------------

    Parameters
    ----------
    calibration_data_root : TYPE
        Path to the camera calibration data. More exactly spoken path
            to the lens sub directory. After calling this function the
            camera is completely reinitialized.
        If the string is empty a currently existing camera connection
            is finished..
    camera_no : TYPE
        DESCRIPTION.
    lens_no : TYPE
        DESCRIPTION.

    Returns
    -------
    None.

    """

    err_code = ax.LMK.iSetNewCamera(calibration_data_root + '/' + camera_no + '/' + lens_no)
    ax.error_code(err_code) # Check for error
示例#13
0
def get_pixel_color(image=dic.IMAGE_TYPES['Color'], line=500, column=500):
    """
    Get a pixel value of a color image.|
    -----------------------------------
    Parameters:
        :lmk:
            | Dispatch('lmk4.LMKAxServer')
        :image: int (default: IMAGE_TYPES['Color'])
            | Index of image
        :line: int (default: 500)
            | Line index
        :column: int (default: 500)
            | Column index
    Returns:
        | The function returns an error if the pixel position is
            outside or the image is a color image.
        :cie_r: float
            | Gets the red component of the pixel value
        :cie_g: float
            | Gets the green component of the pixel value
        :cie_b: float
            | Gets the blue component of the pixel value
    """
    err_code, cie_r, cie_g, cie_b = ax.LMK.iImageGetPixelColor(
        image, line, column)
    ax.error_code(err_code)  # Check for error

    return cie_r, cie_g, cie_b
示例#14
0
def get_color_hist_vals(image=dic.IMAGE_TYPES['Color'],
                        color_space=dic.COLOR_SPACES['XYZ']):
    """
    Get the values of the histogram in a color image.|
    -------------------------------------------------
    The color space is always RGB.
    -----------------------------------------------------------------------
    Parameters:
        :lmk:
            | Dispatch('lmk4.LMKAxServer')
        :image: int (default: IMAGE_TYPES['Color'])
            | Index of object
        :color_space: int (default: COLOR_SPACES['XYZ'])
            | Wished color space from COLOR_SPACES{}
    Returns:
        :num_param: int
            | Number of values
        :x_coords: QStringList
            | x-coordinates
        :hist_values: QStringList
            | Histogram values
    """
    err_code, num_param, x_coords, hist_values \
        = ax.LMK.iGetColorHistogramValues(image, color_space)
    ax.error_code(err_code)  # Check for error

    return num_param, x_coords, hist_values
示例#15
0
def create_image():
    """
    Create template image with the adjusted parameters.|
    ---------------------------------------------------
    Parameters:
        :LMK:
            | Dispatch('lmk4.LMKAxServer')
    """
    err_code = ax.LMK.iTIG_CreateImage()
    ax.error_code(err_code)  # Check for error
示例#16
0
def hide_dialog():
    """
    Make template image dialog invisible.|
    -------------------------------------
    Parameters:
        :LMK:
            | Dispatch('lmk4.LMKAxServer')
    """
    err_code = ax.LMK.iTIG_HideDialog()
    ax.error_code(err_code)  # Check for error
示例#17
0
def delete_image():
    """
    Remove template image from the display.|
    ---------------------------------------
    Template images can only be deleted from a display. If the target is an
    evaluation image, deletion is not possible.
    -----------------------------------------------------------------------
    Parameters:
        :LMK:
            | Dispatch('lmk4.LMKAxServer')
    """
    err_code = ax.LMK.iTIG_DeleteImage()
    ax.error_code(err_code)  # Check for error
示例#18
0
def set_grey_filter(grey_filter_index=0, grey_filter_selected=0):
    """
    Parameters:
        :LMK:
            | Dispatch('lmk4.LMKAxServer')
        :grey_filter_index: int (default: 0)
            | Index of filter, indexes start from '0'
        :grey_filter_selected: int (default: 0)
            | 0 = deselect
            | 1 = select
    """
    err_code = ax.LMK.iSetGreyFilter(grey_filter_index, grey_filter_selected)
    ax.error_code(err_code) # Check for error
示例#19
0
def set_smear(smear=0):
    """
    Set the parameter for smear correction.|
    ---------------------------------------
    Parameters:
        :LMK:
            | Dispatch('lmk4.LMKAxServer')
        :smear: int (default: 0)
            | 0 = no smear
            | !0 = smear correction with at least 10 dark images captures
            | > 10 number of dark images
    """
    err_code = ax.LMK.iSetSmear(smear)
    ax.error_code(err_code) # Check for error
示例#20
0
def set_param_value(parameter, parameter_value):
    """
    Set a certain parameter value.|
    ------------------------------
    Parameters:
        :LMK:
            | Dispatch('lmk4.LMKAxServer')
        :parameter: QString
            | Name of parameter
        :parameter_value: float
            | Value of parameter (if bool, then 0 or 1)
    """
    err_code = ax.LMK.iTIG_SetParameterValue(parameter, parameter_value)
    ax.error_code(err_code)  # Check for error
示例#21
0
def delete(image=dic.IMAGE_TYPES['Color'], index=0):
    """
    Delete a region.|
    ----------------
    Parameters:
        :LMK:
            | Dispatch('lmk4.LMKAxServer')
        :image: int (default: IMAGE_TYPES['Color'])
            | Input: Index of region list (same as image index)
        :index: int (default: 0)
            | Index of region to delete
    """
    err_code = ax.LMK.iDeleteRegion(image, index)
    ax.error_code(err_code)  # Check for error
示例#22
0
def set_focus_factor(focus_factor_no):
    """
    Set a focus factor.|
    -------------------
    See dialog "Camera|Recalibration" in LabSoft main menu.
    -----------------------------------------------------------------------
    Parameters:
        :LMK:
            | Dispatch('lmk4.LMKAxServer')
        :focus_factor: int
            | Index of focus factor
    """
    err_code = ax.LMK.iSetFocusFactor(focus_factor_no)
    ax.error_code(err_code) # Check for error
示例#23
0
def convert_cie_rgb(cie_r=255.0,
                    cie_g=0.0,
                    cie_b=0.0,
                    r_ref=0.0,
                    g_ref=0.0,
                    b_ref=0.0,
                    color_space=dic.COLOR_SPACES['XYZ']):
    """
    Conversion of a color value from CIE-RGB to another color space.|
    ----------------------------------------------------------------
    The color value is given in CIE-RGB and is converted into a color value
    in the target color space. If there is a reference color needed for this
    color space, the reference color is also in CIE-RGB. If there is no
    reference color needed, the three variables can be set to zero.
    The destination color space is given by the value of COLOR_SPACES{}.
    The three components of the destionation color are available
    in '_Out' after the function call returned.
    -----------------------------------------------------------------------
    Parameters:
        :lmk:
            | Dispatch('lmk4.LMKAxServer')
        :cie_r: float (default: 255.0)
            | 	Red component of input color
        :cie_g: float (default: 0.0)
            | 	Green component of input color
        :cie_b: float (default: 0.0)
            | 	Blue component of input color
        :r_ref: float (default: 0.0)
            | Red component of reference color
        :g_ref: float (default: 0.0)
            | Green component of reference color
        :b_ref: float (default: 0.0)
            | Blue component of reference color
        :color_space: int (default: COLOR_SPACES['XYZ'])
            | 	Wished destination color space
    Returns:
        :output_color: array
            | Calculated color in an array shape of (1, 3)
    """
    [err_code, out_i, out_ii, out_iii] = \
        ax.LMK.iGetColor(cie_r, cie_g, cie_b, r_ref, g_ref, b_ref, color_space)
    ax.error_code(err_code)  # Check for error

    # Place new values into an array
    output_color = np.array([[out_i], [out_ii], [out_iii]])
    # Transpose array into (1, 3) shape
    output_color = output_color.T

    return output_color
示例#24
0
def get_standard_statistic(statistic_type=dic.STATISTIC_TYPES['standardColor'],
                           region=0,
                           color_class=0):
    """
    Determine parameter of the standard statistic.|
    ----------------------------------------------
    Parameters:
        :lmk:
            | Dispatch('lmk4.LMKAxServer')
        :statistic_type: int (default: STATISTIC_TYPES['standardColor'])
            | Index of statistic type
        :region: int (default: 0)
            | Index of region in this image
        :color_class: int (default: 0)
            | Index of class or color:
                0 = blue
                1 = green
                2 = red
    Returns:
        :area: float
            | Amount of pixels in area of statistic
        :stat_min: float
            | Minimum value
        :stat_max: float
            | Maximum value
        :stat_mean: float
            | Mean value
        :variance: float
            | Variance (...SD?) in values
    """

    stats = {'Area': [], 'Min': [], 'Max': [], 'Mean': [], 'Variance': []}

    err_code, _, _, _, _, _ = ax.LMK.iGetStandardStatistic2(
        statistic_type, region, color_class)
    ax.error_code(err_code)  # Check for error

    stats['Area'].append(
        ax.LMK.iGetStandardStatistic2(statistic_type, region, color_class)[1])
    stats['Min'].append(
        ax.LMK.iGetStandardStatistic2(statistic_type, region, color_class)[2])
    stats['Max'].append(
        ax.LMK.iGetStandardStatistic2(statistic_type, region, color_class)[3])
    stats['Mean'].append(
        ax.LMK.iGetStandardStatistic2(statistic_type, region, color_class)[4])
    stats['Variance'].append(
        ax.LMK.iGetStandardStatistic2(statistic_type, region, color_class)[5])

    return stats
示例#25
0
def set_target(display_id, display_name):
    """
    Get current target for template image generation.|
    -------------------------------------------------
    Parameters:
        :LMK:
            | Dispatch('lmk4.LMKAxServer')
        :display_id: int
            | -1 = Use given image name
            | 0...N-1 = One of the connected displays
        :display_name: QString
            | Image name is only necessary if 'DisplayID' == -1
    """
    err_code = ax.LMK.iTIG_SetTarget(display_id, display_name)
    ax.error_code(err_code)  # Check for error
示例#26
0
def set_scattered_light(scattered_light=1):
    """
    Use of scattered light correction.|
    ----------------------------------
    Only usable if a parameter set is available in program.
    -----------------------------------------------------------------------
    Parameters:
        :LMK:
            | Dispatch('lmk4.LMKAxServer')
        :scattered_light: int (defualt: 1)
            | 1 = switch on scattered light correction
            | 0 = switch off scattered light correction
    """
    err_code = ax.LMK.iSetScatteredLight(scattered_light)
    ax.error_code(err_code) # Check for error
示例#27
0
def set_max_camera_time(max_time=5.0):
    """
    Set the maximum possible exposure time.|
    ---------------------------------------
    The maximum values is of course restricted by camera properties. But
    you can use an even smaller time to avoid to long meausrement times.
    -----------------------------------------------------------------------
    Parameters:
        :LMK:
            | Dispatch('lmk4.LMKAxServer')
        :max_time: float (default: 5.0)
            | Wished value
    """
    err_code = ax.LMK.iSetMaxCameraTime(max_time)
    ax.error_code(err_code) # Check for error
示例#28
0
def get_number():
    """
    Returns the number of tables in the result tab widget.|
    ------------------------------------------------------
    Parameters:
        :LMK:
            | Dispatch('lmk4.LMKAxServer')
    Returns:
        :tables_no: int
            | Returns the number of tables
    """
    err_code, tables_no = ax.LMK.iTableGetNumber()
    ax.error_code(err_code) # Check for error

    return tables_no
示例#29
0
def set_autoscan(autoscan=1):
    """
    Set use of autoscan algorithm.|
    ------------------------------
    Determination of a good exposure time before the capturing algorithm.
    -----------------------------------------------------------------------
    Parameters:
        :LMK:
            | Dispatch('lmk4.LMKAxServer')
        :autoscan: int (default: 1)
            | 1 = Use autoscan
              0 = Do not use autoscan
    """
    err_code = ax.LMK.iSetAutoscan(autoscan)
    ax.error_code(err_code) # Check for error
示例#30
0
def set_color_correction(col_corr_index=0, col_corr_selected=1):
    """
    Selection of a color correction factor.|
    -------------------------------------------
    Parameters:
        :LMK:
            | Dispatch('lmk4.LMKAxServer')
        :col_corr_index: int (default: 0)
            | List of factors
        :col_corr_selected: int (default: 1)
            | 0 = deselect
            | 1 = select
    """
    err_code = ax.LMK.iSetColorCorr(col_corr_index, col_corr_selected)
    ax.error_code(err_code) # Check for error