The biopixR
package includes multiple images of microbeads as an example to demonstrate its analytical and processing abilities for biological imagery. This sample images display the package’s features, enabling users to experiment with image analysis and manipulation within the contexts of biotechnology and life sciences. Researchers and practitioners can utilize this illustrations to comprehend the application of biopixR
to their individual imaging requirements, whether pertaining to cell biology, microscopy, or any other biological imaging applications.
The biopixR
package features an import function called importImage
. This function acts as a wrapper, integrating the capabilities of the magick
and imager
packages. Since most image processing operations rely on imager
, the importImage
function converts all formats into the imager
class ‘cimg’. It supports importing images in JPEG, PNG, BMP, and TIFF formats.
library(biopixR)
path2img <- system.file("images/beads.png", package = "biopixR")
beads <- importImage(path2img)
plot(beads)
class(beads)
[1] "cimg" "imager_array" "numeric"
The objective of this task is to extract important information from an image consisting of microbeads. As a preliminary step, it is essential to distinguish between individual microbeads and acquire their corresponding coordinates or positions. The objectDetection
function can perform segmentation using either thresholding or edge detection. The thresholding method is particularly suited for images with high and inhomogeneous backgrounds, as it includes background correction by solving the Screened Poisson Equation before applying the threshold. This allows for the detection of low-contrast objects with inconsistent backgrounds, such as transparent microbeads. When edge detection is chosen, a modified Canny edge detector, provided by the edgeDetection
function, is used. This modified function reconnects line ends to nearby contours, ensuring continuous contours even with lower smoothing settings. In summary, the objectDetection
function gathers detailed information about the microbeads, enabling the identification and differentiation of individual objects. This process helps derive precise coordinates for each object in the image, which serves as the foundation for further analysis and characterization of the microbeads within the biopixR
package.
res_objectDetection <-
objectDetection(beads, method = 'edge', alpha = 1, sigma = 0)
This function generates a list of objects. Let’s examine the specific outcomes and explore methods for visualizing them, starting with the center coordinates of the microbeads:
plot(beads)
with(
res_objectDetection$centers,
points(
res_objectDetection$centers$mx,
res_objectDetection$centers$my,
col = factor(res_objectDetection$centers$value),
pch = 19
)
)
Upon closer examination, it is evident that each individual microbead is identified accurately by a singular point at its center, and their distinctiveness is conveyed through varying colors, aligning with our intended objective. However, the identification of clotted microbeads, referred to as doublets or multiplets, deviates from the expected pattern. Notably, not every visually distinguishable microbead is marked with a distinct color. The observed behavior, where doublets are identified as a single entity, occurs because their edges disappear along the contact surface. The same principle applies to multiplets; the consecutive edges of clustered beads cause them to be treated as a single, larger object.
Let’s examine the next output from objectDetection
. This function captures the coordinates of labeled regions, providing precise details about the position of each microbead. By leveraging another function within the package, changePixelColor
, we can selectively color-specific coordinates in a ‘cimg’. Thus, we can apply this function to highlight all the extracted coordinates in the microbead image and assess whether the outcome aligns with our expectations.
changePixelColor(
beads,
res_objectDetection$coordinates,
color = factor(res_objectDetection$coordinates$value),
visualize = TRUE
)
The visual depiction shows that all relevant coordinates were successfully retrieved, with each variant (single microbeads, doublets, and multiplets) colored accordingly. As previously stated, these clotted microbeads should be excluded from further consideration. The difference in size serves as a critical factor for efficient sorting and subsequent analysis. Therefore, the selected parameter for addressing these microbeads will be their size. The next section will provide a detailed explanation of the sizeFilter
application process.
Before delving into the available filter functions in the package, let us first examine the internal visualization feature of the objectDetection
function. The edges identified by the edgeDetection
function are visually emphasized with color, simplifying the adjustment of the threshold parameter (alpha
) in the objectDetection
function. In addition, the identified centers are represented as green circles. This visualization is particularly useful in determining the smoothing factor (sigma
). Sometimes, smoothing is necessary to improve the recognition of complete objects and prevent the marking of fragmented edges.
res_objectDetection$marked_objects |> plot()
Nonetheless, a crucial differentiation occurs in obtaining the highlighted microbeads as a ‘cimg’, which opens up possibilities for the creation of an interactive tool using tcltk
. This step facilitates the development of an interactive interface, empowering users to dynamically explore the adjustment of various variables and observe the corresponding shifts in detected microbeads. The interactive interface is presented through the interactive_objectDetection
function within the biopixR
package.
As previously discussed, the ‘edge’ method requires alpha
and sigma
as input parameters, which significantly impact the final result. To simplify the process of determining these parameters and to facilitate automation and batch processing, two methods are provided for their automated calculation:
Both methods rely on a fitness function that extracts shape information using another function (shapeFeatures
). This fitness function evaluates the results with different input parameters, assuming circular-shaped objects. While the grid search method can be time-consuming as it tests every possible combination, the Pareto front optimization method samples and analyzes a subset of combinations, estimating the optimal parameters more quickly.
It should be noted that the threshold function can also be employed, which does not require any additional input. Although the threshold method is a valid approach for segmentation, it has the disadvantage of merging objects in close proximity that would be considered distinct by the edge detector. Consequently, the decision between greater accuracy with parameter input or time consuming calculation and the more straightforward thresholding approach depends on the user’s specific requirements.
res_threshold_object <- objectDetection(beads, method = 'threshold')
res_threshold_object$marked_objects |> plot()