Title: | Extra Image Processing Library Based on 'imager' |
---|---|
Description: | Provides advanced functions for image processing based on the package 'imager'. |
Authors: | Shota Ochi [aut, cre, cph], Guoshen Yu [ctb, cph], Guillermo Sapiro [ctb, cph], Catalina Sbert [ctb, cph], Image Processing On Line [cph], Pascal Getreuer [ctb, cph] |
Maintainer: | Shota Ochi <[email protected]> |
License: | GPL-3 |
Version: | 2.0.0 |
Built: | 2024-11-07 04:43:01 UTC |
Source: | https://github.com/shotaochi/imagerextra |
Balance color of image by Simplest Color Balance
BalanceSimplest(im, sleft, sright, range = c(0, 255))
BalanceSimplest(im, sleft, sright, range = c(0, 255))
im |
a grayscale image of class cimg |
sleft |
left saturation percentage. sleft can be specified by numeric or string, e.g. 1 and "1%". note that sleft is a percentile. |
sright |
right saturation percentage. sright can be specified by numeric or string. note that sright is a percentile. |
range |
this function assumes that the range of pixel values of of input image is [0,255] by default. you may prefer [0,1]. |
a grayscale image of class cimg
Shota Ochi
Nicolas Limare, Jose-Luis Lisani, Jean-Michel Morel, Ana Belen Petro, and Catalina Sbert, Simplest Color Balance, Image Processing On Line, 1 (2011), pp. 297-315. doi:10.5201/ipol.2011.llmps-scb
dev.new() par(mfcol = c(1,2)) boats_g <- grayscale(boats) plot(boats_g, main = "Original") BalanceSimplest(boats_g, 1, 1) %>% plot(., main = "Simplest Color Balance")
dev.new() par(mfcol = c(1,2)) boats_g <- grayscale(boats) plot(boats_g, main = "Original") BalanceSimplest(boats_g, 1, 1) %>% plot(., main = "Simplest Color Balance")
DCT2D computes two dimensional discrete cosine transformation. IDCT2D computes two dimensional inverse discrete cosine transformation.
DCT2D(imormat, returnmat = FALSE) IDCT2D(imormat, returnmat = FALSE)
DCT2D(imormat, returnmat = FALSE) IDCT2D(imormat, returnmat = FALSE)
imormat |
a grayscale image of class cimg or a numeric matrix |
returnmat |
if returnmat is TRUE, returns numeric matrix. if FALSE, returns a grayscale image of class cimg. |
a grayscale image of class cimg or a numeric matrix
Shota Ochi
Makhoul, J. (1980). A fast cosine transform in one and two dimensions. IEEE Transactions on Acoustics, Speech, and Signal Processing. 28 (1): 27-34.
g <- grayscale(boats) layout(matrix(1:2, 1, 2)) plot(g, main = "Original") gg <- DCT2D(g) %>% IDCT2D() %>% plot(main = "Transformed") mean((g - gg)^2)
g <- grayscale(boats) layout(matrix(1:2, 1, 2)) plot(g, main = "Original") gg <- DCT2D(g) %>% IDCT2D() %>% plot(main = "Transformed") mean((g - gg)^2)
denoise image by DCT denoising
DenoiseDCT(im, sdn, flag_dct16x16 = FALSE)
DenoiseDCT(im, sdn, flag_dct16x16 = FALSE)
im |
a grayscale image of class cimg |
sdn |
standard deviation of Gaussian white noise |
flag_dct16x16 |
flag_dct16x16 determines the size of patches. if TRUE, the size of patches is 16x16. if FALSE, the size if patches is 8x8. |
a grayscale image of class cimg
Shota Ochi
Guoshen Yu, and Guillermo Sapiro, DCT Image Denoising: a Simple and Effective Image Denoising Algorithm, Image Processing On Line, 1 (2011), pp. 292-296. doi:10.5201/ipol.2011.ys-dct
dev.new() par(mfcol = c(1,2)) boats_g <- grayscale(boats) boats_noisy <- imnoise(dim = dim(boats_g), sd = 0.05) + boats_g plot(boats_noisy, main = "Noisy Boats") DenoiseDCT(boats_g, 0.05) %>% plot(., main = "Denoised Boats")
dev.new() par(mfcol = c(1,2)) boats_g <- grayscale(boats) boats_noisy <- imnoise(dim = dim(boats_g), sd = 0.05) + boats_g plot(boats_noisy, main = "Noisy Boats") DenoiseDCT(boats_g, 0.05) %>% plot(., main = "Denoised Boats")
This photograph was downloaded from http://gahag.net/img/201603/03s/gahag-0062116383-1.jpg. Its size was reduced by half to speed up loading and save space.
dogs
dogs
an image of class cimg
http://gahag.net/img/201603/03s/gahag-0062116383-1.jpg
computes the parameters, t_down and t_up, and then apply double plateaus histogram equalization.
EqualizeADP(im, n = 5, N = 1000, range = c(0, 255), returnparam = FALSE)
EqualizeADP(im, n = 5, N = 1000, range = c(0, 255), returnparam = FALSE)
im |
a grayscale image of class cimg |
n |
window size to determine local maximum |
N |
the number of subintervals of histogram |
range |
range of the pixel values of image. this function assumes that the range of pixel values of of an input image is [0,255] by default. you may prefer [0,1]. |
returnparam |
if returnparam is TRUE, returns the computed parameters: t_down and t_up. |
a grayscale image of class cimg or a numericvector
Shota Ochi
Kun Liang, Yong Ma, Yue Xie, Bo Zhou ,Rui Wang (2012). A new adaptive contrast enhancement algorithm for infrared images based on double plateaus histogram equalization. Infrared Phys. Technol. 55, 309-315.
g <- grayscale(dogs) layout(matrix(1:2, 1, 2)) plot(g, main = "Original") EqualizeADP(g) %>% plot(main = "Contrast Enhanced")
g <- grayscale(dogs) layout(matrix(1:2, 1, 2)) plot(g, main = "Original") EqualizeADP(g) %>% plot(main = "Contrast Enhanced")
enhances contrast of image by double plateaus histogram equalization.
EqualizeDP(im, t_down, t_up, N = 1000, range = c(0, 255))
EqualizeDP(im, t_down, t_up, N = 1000, range = c(0, 255))
im |
a grayscale image of class cimg |
t_down |
lower threshold |
t_up |
upper threshold |
N |
the number of subintervals of histogram |
range |
range of the pixel values of image. this function assumes that the range of pixel values of of an input image is [0,255] by default. you may prefer [0,1]. |
a grayscale image of class cimg
Shota Ochi
Kun Liang, Yong Ma, Yue Xie, Bo Zhou ,Rui Wang (2012). A new adaptive contrast enhancement algorithm for infrared images based on double plateaus histogram equalization. Infrared Phys. Technol. 55, 309-315.
g <- grayscale(dogs) layout(matrix(1:2, 1, 2)) plot(g, main = "Original") EqualizeDP(g, 20, 186) %>% plot(main = "Contrast Enhanced")
g <- grayscale(dogs) layout(matrix(1:2, 1, 2)) plot(g, main = "Original") EqualizeDP(g, 20, 186) %>% plot(main = "Contrast Enhanced")
enhance contrast of image by piecewise affine histogram equalization
EqualizePiecewise(im, N, smax = 255, smin = 0, range = c(0, 255))
EqualizePiecewise(im, N, smax = 255, smin = 0, range = c(0, 255))
im |
a grayscale image of class cimg |
N |
number of subintervals of partition. N controls how the input gray levels will be mapped in the output image. if N is large, Piecewise Affine Equalization and Histogram Equalization are very similar. |
smax |
maximum value of slopes. if smax is small, contrast enhancement is suppressed. |
smin |
minimum value of slopes. if smin is large, contrast enhancement is propelled, and saturations occur excessively. |
range |
range of the pixel values of image. this function assumes that the range of pixel values of of an input image is [0,255] by default. you may prefer [0,1]. if you change range, you should change smax. one example is this (smax = range[2] - range[1]). |
a grayscale image of class cimg
Shota Ochi
Jose-Luis Lisani, Ana-Belen Petro, and Catalina Sbert, Color and Contrast Enhancement by Controlled Piecewise Affine Histogram Equalization, Image Processing On Line, 2 (2012), pp. 243-265. doi:10.5201/ipol.2012.lps-pae
dev.new() par(mfcol = c(1,2)) boats_g <- grayscale(boats) plot(boats_g, main = "Original") EqualizePiecewise(boats_g, 10) %>% plot(., main = "Piecewise Affine Equalization")
dev.new() par(mfcol = c(1,2)) boats_g <- grayscale(boats) plot(boats_g, main = "Original") EqualizePiecewise(boats_g, 10) %>% plot(., main = "Piecewise Affine Equalization")
store hue of color image
GetHue(imcol)
GetHue(imcol)
imcol |
a color image of class cimg |
a color image of class cimg
Shota Ochi
GetHue(boats)
GetHue(boats)
compute average of RGB channels
Grayscale(imcol)
Grayscale(imcol)
imcol |
a color image of class cimg |
a grayscale image of class cimg
Shota Ochi
Grayscale(boats) %>% plot
Grayscale(boats) %>% plot
imagerExtra is built on imager. imager by Simon Simon Barthelme provides an interface with CImg that is a C++ library for image processing. imager makes functions of CImg accessible from R and adds many utilities for accessing and working with image data from R. imagerExtra provides advanced functions for image processing based on imager.
OCR and OCR_data are wrappers for ocr and ocr_data of tesseract package. You need to install tesseract package to use these functions.
OCR(imorpx, engine = tesseract::tesseract("eng"), HOCR = FALSE) OCR_data(imorpx, engine = tesseract::tesseract("eng"))
OCR(imorpx, engine = tesseract::tesseract("eng"), HOCR = FALSE) OCR_data(imorpx, engine = tesseract::tesseract("eng"))
imorpx |
a grayscale image of class cimg, a color image of class cimg, or a pixel set |
engine |
a tesseract engine. See the reference manual of tesseract for detail. |
HOCR |
if TRUE return results as HOCR xml instead of plain text |
Shota Ochi
hello <- DenoiseDCT(papers, 0.01) %>% ThresholdAdaptive(., 0.1, range = c(0,1)) if (requireNamespace("tesseract", quietly = TRUE)) { OCR(hello) %>% cat OCR_data(hello) }
hello <- DenoiseDCT(papers, 0.01) %>% ThresholdAdaptive(., 0.1, range = c(0,1)) if (requireNamespace("tesseract", quietly = TRUE)) { OCR(hello) %>% cat OCR_data(hello) }
This photograph was filmed by Shota Ochi.
papers
papers
an image of class cimg
restore hue of color image
RestoreHue(im, hueim)
RestoreHue(im, hueim)
im |
a grayscale image of class cimg |
hueim |
a color image of class cimg |
a color image of class cimg
Shota Ochi
g <- Grayscale(boats) hue <- GetHue(boats) layout(matrix(1:2, 1, 2)) plot(g, main = "Original") RestoreHue(g, hue) %>% plot(main="Resotred")
g <- Grayscale(boats) hue <- GetHue(boats) layout(matrix(1:2, 1, 2)) plot(g, main = "Original") RestoreHue(g, hue) %>% plot(main="Resotred")
iterative image segmentation with Chan-Vese model
SegmentCV( im, mu = 0.25, nu = 0, lambda1 = 1, lambda2 = 1, tol = 1e-04, maxiter = 500, dt = 0.5, initial, returnstep )
SegmentCV( im, mu = 0.25, nu = 0, lambda1 = 1, lambda2 = 1, tol = 1e-04, maxiter = 500, dt = 0.5, initial, returnstep )
im |
a grayscale image of class cimg |
mu |
length penalty |
nu |
area penalty |
lambda1 |
fit weight inside the curve |
lambda2 |
fit weight outside the curve |
tol |
convergence tolerance |
maxiter |
maximum number of iterations |
dt |
time step |
initial |
"interactive" or a grayscale image of class cimg. you can define initial condition as a rectangle shape interactively if initial is "interactive". If initial is a grayscale image of class cimg, pixels whose values are negative will be treated as outside of contour. pixels whose values are non-negative will be treated as inside of contour. checker board condition will be used if initial is not specified. |
returnstep |
a numeric vector that determines which result will be returned. 0 means initial condition, and 1 means the result after 1 iteration. final result will be returned if returnstep is not specified. |
a pixel set or a list of lists of numeric and pixel set
Shota Ochi
Pascal Getreuer (2012). Chan-Vese Segmentation. Image Processing On Line 2, 214-224.
layout(matrix(1:2, 1, 2)) g <- grayscale(dogs) plot(g, main = "Original") SegmentCV(g, lambda2 = 15) %>% plot(main = "Binarized")
layout(matrix(1:2, 1, 2)) g <- grayscale(dogs) plot(g, main = "Original") SegmentCV(g, lambda2 = 15) %>% plot(main = "Binarized")
Correct inhomogeneous background of image by solving Screened Poisson Equation
SPE(im, lamda, s = 0.1, range = c(0, 255))
SPE(im, lamda, s = 0.1, range = c(0, 255))
im |
a grayscale image of class cimg |
lamda |
this function corrects inhomogeneous background while preserving image details. lamda controls the trade-off. when lamda is too large, this function acts as an edge detector. |
s |
saturation percentage. this function uses |
range |
this function assumes that the range of pixel values of of an input image is [0,255] by default. you may prefer [0,1]. |
a grayscale image of class cimg
Shota Ochi
Jean-Michel Morel, Ana-Belen Petro, and Catalina Sbert, Screened Poisson Equation for Image Contrast Enhancement, Image Processing On Line, 4 (2014), pp. 16-29. doi:10.5201/ipol.2014.84
dev.new() par(mfcol = c(1,2)) boats_g <- grayscale(boats) plot(boats_g, main = "Original") SPE(boats_g, 0.1) %>% plot(main = "Screened Poisson Equation")
dev.new() par(mfcol = c(1,2)) boats_g <- grayscale(boats) plot(boats_g, main = "Original") SPE(boats_g, 0.1) %>% plot(main = "Screened Poisson Equation")
Local Adaptive Thresholding
ThresholdAdaptive(im, k, windowsize = 17, range = c(0, 255))
ThresholdAdaptive(im, k, windowsize = 17, range = c(0, 255))
im |
a grayscale image of class cimg |
k |
a numeric in the range [0,1]. when k is high, local threshold values tend to be lower. when k is low, local threshold value tend to be higher. |
windowsize |
windowsize controls the number of local neighborhood |
range |
this function assumes that the range of pixel values of of input image is [0,255] by default. you may prefer [0,1]. Note that range determines the max standard deviation. The max standard deviation plays an important role in this function. |
a pixel set
Shota Ochi
Faisal Shafait, Daniel Keysers, Thomas M. Breuel, "Efficient implementation of local adaptive thresholding techniques using integral images", Proc. SPIE 6815, Document Recognition and Retrieval XV, 681510 (28 January 2008)
layout(matrix(1:4, 2, 2)) plot(papers, main = "Original") threshold(papers) %>% plot(main = "A variant of Otsu") ThresholdAdaptive(papers, 0, range = c(0,1)) %>% plot(main = "local adaptive (k = 0)") ThresholdAdaptive(papers, 0.2, range = c(0,1)) %>% plot(main = "local adaptive (k = 0.2)")
layout(matrix(1:4, 2, 2)) plot(papers, main = "Original") threshold(papers) %>% plot(main = "A variant of Otsu") ThresholdAdaptive(papers, 0, range = c(0,1)) %>% plot(main = "local adaptive (k = 0)") ThresholdAdaptive(papers, 0.2, range = c(0,1)) %>% plot(main = "local adaptive (k = 0.2)")
automatic fuzzy thresholding based on particle swarm optimization
ThresholdFuzzy( im, n = 50, maxiter = 100, omegamax = 0.9, omegamin = 0.1, c1 = 2, c2 = 2, mutrate = 0.2, vmaxcoef = 0.1, intervalnumber = 1000, returnvalue = FALSE )
ThresholdFuzzy( im, n = 50, maxiter = 100, omegamax = 0.9, omegamin = 0.1, c1 = 2, c2 = 2, mutrate = 0.2, vmaxcoef = 0.1, intervalnumber = 1000, returnvalue = FALSE )
im |
a grayscale image of class cimg |
n |
swarm size |
maxiter |
maximum iterative time |
omegamax |
maximum inertia weight |
omegamin |
minimum inertia weight |
c1 |
acceleration coefficient |
c2 |
acceleration coefficient |
mutrate |
rate of gaussian mutation |
vmaxcoef |
coefficient of maximum velocity |
intervalnumber |
interval number of histogram |
returnvalue |
if returnvalue is TRUE, returns a threshold value. if FALSE, returns a pixel set. |
a pixel set or a numeric
Shota Ochi
Linyi Li, Deren Li (2008). Fuzzy entropy image segmentation based on particle swarm optimization. Progress in Natural Science.
g <- grayscale(boats) layout(matrix(1:2, 1, 2)) plot(g, main = "Original") ThresholdFuzzy(g) %>% plot(main = "Fuzzy Thresholding")
g <- grayscale(boats) layout(matrix(1:2, 1, 2)) plot(g, main = "Original") ThresholdFuzzy(g) %>% plot(main = "Fuzzy Thresholding")
Segments a grayscale image into several gray levels. Multilevel thresholding selection based on the artificial bee colony algorithm is used when thr is not a numeric vector. Preset parameters for fast computing is used when thr is "fast". Preset parameters for precise computing is used when thr is "precise". You can tune the parameters if thr is "manual". Also you can specify the values of thresholds by setting thr as a numeric vector.
ThresholdML( im, k, thr = "fast", sn = 30, mcn = 100, limit = 100, intervalnumber = 1000, returnvalue = FALSE )
ThresholdML( im, k, thr = "fast", sn = 30, mcn = 100, limit = 100, intervalnumber = 1000, returnvalue = FALSE )
im |
a grayscale image of class cimg |
k |
level of thresholding. k is ignored when thr is a numeric vector. |
thr |
thresholds, either numeric vector, or "fast", or "precise", or "manual". |
sn |
population size. sn is ignored except when thr is "manual". |
mcn |
maximum cycle number. mcn is ignored except when thr is "manual". |
limit |
abandonment criteria. limit is ignored except when thr is "manual". |
intervalnumber |
interval number of histogram. intervalnumber is ignored except when thr is "manual". |
returnvalue |
if returnvalue is TRUE, returns threshold values. if FALSE, returns a grayscale image of class cimg. |
a grayscale image of class cimg or a numeric vector
Shota Ochi
Ming-HuwiHorng (2011). Multilevel thresholding selection based on the artificial bee colony algorithm for image segmentation. Expert Systems with Applications.
g <- grayscale(boats) ThresholdML(g, k = 2) %>% plot
g <- grayscale(boats) ThresholdML(g, k = 2) %>% plot
compute threshold value by Iterative Triclass Threshold Technique
ThresholdTriclass( im, stopval = 0.01, repeatnum, intervalnumber = 1000, returnvalue = FALSE )
ThresholdTriclass( im, stopval = 0.01, repeatnum, intervalnumber = 1000, returnvalue = FALSE )
im |
a grayscale image of class cimg |
stopval |
value to determine whether stop iteration of triclass thresholding or not. Note that if repeat is set, stop is ignored. |
repeatnum |
number of repetition of triclass thresholding |
intervalnumber |
interval number of histogram |
returnvalue |
if returnvalue is TRUE, ThresholdTriclass returns threshold value. if FALSE, ThresholdTriclass returns pixset. |
a pixel set or a numeric
Shota Ochi
Cai HM, Yang Z, Cao XH, Xia WM, Xu XY (2014). A New Iterative Triclass Thresholding Technique in Image Segmentation. IEEE TRANSACTIONS ON IMAGE PROCESSING.
g <- grayscale(boats) layout(matrix(1:4, 2, 2)) plot(boats, main = "Original") plot(g, main = "Grayscale") threshold(g) %>% plot(main = "A Variant of Otsu") ThresholdTriclass(g) %>% plot(main = "Triclass")
g <- grayscale(boats) layout(matrix(1:4, 2, 2)) plot(boats, main = "Original") plot(g, main = "Grayscale") threshold(g) %>% plot(main = "A Variant of Otsu") ThresholdTriclass(g) %>% plot(main = "Triclass")