Statistical image features

In this sample, statistical features (min, max, median, average value, standard deviation) of images are calculated. The following functions are used for this:

Application

This project contains a File Source into which any RGB images can be loaded. These are converted in the program into grayscale images and analyzed with regard to various statistics. The result values are drawn in the image and can be viewed in the ADS Image Watch under ipImageRes.

Program

// Prepare images
hr := F_VN_ConvertColorSpace(ipImageIn, ipImageIn, TCVN_CST_RGB_TO_GRAY, hr);
hr := F_VN_CopyImage(ipImageIn, ipImageRes, hr);

// Calculate image statistics
hr := F_VN_MinPixelValue(
    ipImage     :=  ipImageIn,
    aMinValue   :=  aMin,
    aPosition   :=  aPos,
    hrPrev      :=  hr
);
hr := F_VN_MaxPixelValue(
    ipImage     :=  ipImageIn,
    aMaxValue   :=  aMax,
    aPosition   :=  aPos,
    hrPrev      :=  hr
);
hr := F_VN_ImageMedian(
    ipSrcImage  :=  ipImageIn,
    aMedian     :=  aMedian,
    hrPrev      :=  hr
);
hr := F_VN_ImageAverageStdDev(
    ipSrcImage  :=  ipImageIn,
    aAverage    :=  aAverage,
    aStdDev     :=  aStdDev,
    hrPrev      :=  hr
);

// Draw results
sText := CONCAT('Min: ', LREAL_TO_FMTSTR(aMin[0], 2, TRUE ));
hr := F_VN_PutLabel(sText, ipImageRes, nTextX, (nTextYBase + (1 * nTextYIncrement)), fFontScale, hr);
sText := CONCAT('Max: ', LREAL_TO_FMTSTR(aMax[0], 2, TRUE ));
hr := F_VN_PutLabel(sText, ipImageRes, nTextX, (nTextYBase + (2 * nTextYIncrement)), fFontScale, hr);
sText := CONCAT('Median: ', LREAL_TO_FMTSTR(aMedian[0], 2, TRUE ));
hr := F_VN_PutLabel(sText, ipImageRes, nTextX, (nTextYBase + (3 * nTextYIncrement)), fFontScale, hr);
sText := CONCAT('Average: ', LREAL_TO_FMTSTR(aAverage[0], 2, TRUE ));
hr := F_VN_PutLabel(sText, ipImageRes, nTextX, (nTextYBase + (4 * nTextYIncrement)), fFontScale, hr);
sText := CONCAT('StdDev: ', LREAL_TO_FMTSTR(aStdDev[0], 2, TRUE ));
hr := F_VN_PutLabel(sText, ipImageRes, nTextX, (nTextYBase + (5 * nTextYIncrement)), fFontScale, hr);

hr := F_VN_TransformIntoDisplayableImage(ipImageIn, ipImageInDisp, hr);
hr := F_VN_TransformIntoDisplayableImage(ipImageRes, ipImageResDisp, hr);

The PLC library Tc2_Utilities is required for the function LREAL_TO_FMTSTR.