imagerExtra provides advanced functions for image processing based on the R package imager.
The functions in imagerExtra are classified into 4 groups by their functions.
See below to know what functions imagerExtra provides.
Most of the functions in imagerExtra are for grayscale image.
See the vignette Treating Color Image with imagerExtra if you want to treat color image with imagerExtra.
Let’s prepare grayscale images.
library(imagerExtra)
g <- grayscale(boats)
gd <- grayscale(dogs)
layout(matrix(1:2,1,2))
plot(g, main = "boats")
plot(gd, main = "dogs")
The functions for contrast enhancement are
EqualizePiecewise has three parameters: N, smin, and smax.
However, we should not change smin.
See Jose-Luis Lisani, et al., IPOL, 2 (2012), pp. 243-265. for detail.
The parameter N controls how the input gray level will be mapped in the output image.
We don’t have a priori choice for N. You will tune N mainly.
The parameter smax controls the upper limit of contrast stretching.
If you want to prevent excessive enhancement of contrast, you should make smax low.
BalanceSimplest saturates a percentage sleft % of the pixels on the left side of the histogram,
and a percentage sright % of the pixels on the right side of the histogram.
See Nicolas Limare, et al., IPOL, 1 (2011), pp. 297-315. for detail.
The distinction of SPE is that SPE corrects the inhomogeneous background of image.
See Jean-Michel Morel, et al., IPOL, 4 (2014), pp. 16-29. for detail.
The parameter lamda controls how strong corrects inhomogeneous background of image.
SPE corrects inhomogeneous background strongly if lamda is large.
Double plateaus histogram equalization (DPHE) enhances contrast of image while preventing over-enhancement of background noise and protecting details of objects in images.
DPHE modifies original histogram as shown below, and then apply histogram equalization. $$ H_{m}(g) = \begin{cases} T_{UP} & h(g) >= T_{UP} \\ h(g) & T_{DOWN} < h(g) < T_{UP} \\ T_{DOWN} & h(g) <= T_{DOWN} \end{cases} $$ where g is the gray level, h(g) is the original histogram, and Hm(g) is the modified histogram.
You will tune the two key parameters, TDOWN and TUP.
The function for image denoising is
DCT denoising is a simple and effective denoising algorithm using local DCT thresholding.
See Guoshen Yu, and Guillermo Sapiro, IPOL, 1 (2011), pp. 292-296. for detail.
The parameter sdn determines how strong denoise a image.
Noise is strongly denoised if sdn is large.
The parameter flag_dct16x16 determines window size of local patches.
DenoiseDCT uses 8x8 windows or 16x16 window.
Larger window size does not bring significant improvement when noise level is low.
Larger window size outperforms significantly smaller window size when noise level is low.
noisy <- g + imnoise(dim = dim(g), sd = 0.1)
layout(matrix(c(1,3,2,4), 2, 2))
plot(g, main = "Original")
plot(noisy, main = "Noisy Boats")
DenoiseDCT(noisy, 0.1) %>% plot(., main = "Denoised (8x8 window)")
DenoiseDCT(noisy, 0.1, flag_dct16x16 = TRUE) %>% plot(., main = "Denoised (16x16 window)")
The functions for image segmentation are
Iterative triclass thresholding is an iterative thresholding technique.
We need to set a rule to stop iteration.
We have two options.
gdogs <- grayscale(dogs)
layout(matrix(1:4, 2, 2, byrow = TRUE))
plot(gdogs, main = "Original", axes=F)
ThresholdTriclass(gdogs, stopval = 0.001) %>% plot(main = "stopval = 0.001")
ThresholdTriclass(gdogs, repeatnum = 1) %>% plot(main = "repeatnum = 1")
ThresholdTriclass(gdogs, repeatnum = 3) %>% plot(main = "repeatnum = 3")
Local adaptive thresholding can extract objects from inhomogeneous background.
You will tune the two paramters k and windowsize.
Note that the parameter range determines max standard deviation.
you should set range as [0,1] if you treat a image whose pixel values are in [0,1].
Fuzzy thresholding is an automatic thresholding based on fuzzy set theory.
Multilevel thresholding segments an image into several gray levels.
You can specify level of thresholds or values of thresholds.
The values of thresholds are computed automatically if you specify the level of thresholds.
Chan-Vese segmentation (CVS) is an iterative region-based segmentation algorithm.
CVS can extract objects whose pixel values aren’t homogeneous.
This is the distinction of CVS.
SegmentCV has many arguments and most of the arguments are key paramters.
It’s too many to explain briefly.
See Pascal Getreuer (2012). Chan-Vese Segmentation. Image Processing On Line 2, 214-224. for detail.
layout(matrix(1:2, 1, 2))
plot(gd, main = "Original")
SegmentCV(gd, lambda2 = 15) %>% plot(main = "Chan-Vese")
The functions classified as others are
These functions are for treating color image with imagerExtra.
See the vignette Treating Color Image with imagerExtra for detail.
These functions are wrappers for ocr function and ocr_data function of the R package tesseract.
See the vignette Optical Character Recognition with imagerExtra for detail.