机器学习
R语言
R语言与黑白照片
R语言与阈值
OCR文字识别
R语言与OCR文字识别
R语言图像处理
R语言黑白照片
# Sun Sep 27 00:27:20 2020 -
# 字符编码:UTF-8
# R 版本:R x64 4.0.2 for window 10
# cgh163email@163.com
# 个人笔记不负责任
# —— 拎了个梨🍐
.rs.restartR()
rm(list=ls());gc()
library(magick)
require(image.binarization)
# image.binarization对图像进行二值化以增强光学字符识别
#它是依赖于magick的
#
f <- system.file("extdata", "doxa-example.png", package = "image.binarization")
img <- image_read(f)
# Sun Sep 27 00:34:47 2020 -# 去色:-----------------------------
img2 <- image_convert(img, format = "PGM", colorspace = "Gray")
par(mfrow=c(1,2))
plot(img)
plot(img2,main='image_convert去色')
# 灰度直方图的阈值选择方法:
# 请注意,重要的是,您必须以整数形式提供窗口/阈值/对比度限制,minN,字形参数(例如,在75L中),而其他参数则以数字形式提供。
#
binary <- image_binarization(img, type = "otsu")
binary
# 贝恩森:窗口(75L),k(0.2),阈值(100L),对比度极限(25L):
binary <- image_binarization(img,
type = "bernsen",
opts = list(
window = 50L,
k = 0.2,
threshold = 50L
))
binary
# 尼布莱克: window(75L), k(0.2):
binary <- image_binarization(img, type = "niblack", opts = list(window = 75L, k = 0.2))
binary
# 卫星式样:窗(75L),k(0.2):
binary <- image_binarization(img, type = "sauvola")
binary
# 狼
binary <- image_binarization(img, type = "wolf")
binary
# nick: window(75L), k(-0.2):
binary <- image_binarization(img, type = "nick", opts = list(window = 75L, k = -0.2))
binary
# gatos: window(75L), k(0.2), glyph(60L):
binary <- image_binarization(img, type = "gatos", opts = list(window = 75L, k = 0.2, glyph = 50L))
binary
# su: window(75L), minN(75L)
binary <- image_binarization(img, type = "su", opts = list(window = 20L))
binary
# trsingh: window(75L), k(0.2)
binary <- image_binarization(img, type = "trsingh")
binary
# bataineh:无:
binary <- image_binarization(img, type = "bataineh")
binary
# wan: window(75L), k(0.2):
binary <- image_binarization(img, type = "wan")
binary
# isauvola: window(75L), k(0.2):
binary <- image_binarization(img, type = "isauvola", opts = list(window = 75L, k = 0.2))
binary