Abstract
The automatic (linear) ring border detection algoritm requires images to be adequately prepared to reduce detectin mistakes to a useful level. Questions open are: 1 - which kind of preparation could help? 2 - how to apply the preparation on over 600 cores?-
(*) search: “gimp export tiff with only 3 channels” answer: “https://graphicdesign.stackexchange.com/questions/45265/export-png-image-without-alpha-channel-in-gimp” “In GIMP, alpha channels exist per layer. If you go to the layers dialogue (Ctrl+L), right-click on your layer, there is an item Remove Alpha Channel, which does what you want. If it is greyed out, your layer does not have an alpha channel.”
library(tidyverse)
library(measuRing)
library(imager)
plotCore <- function(grey, rb) {
cc <- min(dim(grey))/2
bc <- c(1:max(dim(grey)))[!is.na(rb$borders)]
brd <- data.frame( x = bc, y = cc)
grey %>%
as.cimg %>%
as.data.frame %>%
ggplot(aes(y, x)) +
geom_raster(aes(fill = value)) +
scale_fill_gradient(low="black",high="white") +
theme(legend.position = "none") +
geom_point(data = brd, aes(x, jitter(y, cc)), colour = "white", shape = 4)
}
plotSmoothed <- function(rb, last.year) {
coreID <- names(rb)[1]
SmtdG <- 'Smoothed gray'
rb1 <- rb %>%
rename(SmtdG = 1) %>%
mutate(col = 1:nrow(.))
rb2 <- rb1 %>%
filter(!is.na(borders)) %>%
mutate(ringn = nrow(.):1,
year = last.year:(last.year-nrow(.)+1))
ggplot() +
geom_line(data = rb1, aes(col, SmtdG), colour = "grey") +
geom_point(data = rb2, aes(col, SmtdG), colour = "black", shape = 4) +
geom_text(data = rb2, aes(col, SmtdG, label = year), hjust = 2, size = 3, angle = 90)
}
processCore <- function(image,
plot = T, last.year = NULL,...) {
grey <- imageTogray(image)
rb <- ringBorders(grey)
if(is.null(last.year)) last.year <- sum(!is.na(rb$borders))
print(last.year)
core <- plotCore(grey, rb)
smtd <- plotSmoothed(rb, last.year)
ggpubr::ggarrange(smtd, core,
ncol = 1, nrow = 2, align = "v")
# title = coreID
}
img_pth <- "measuRing_demo_imgs"
last.year <- 2011
imgs <- dir(img_pth, pattern = "P")
imgs
## [1] "P105_a.png" "P105_a.tif" "P105_b.tif" "P105_c.tif" "P105_d.tif"
image <- paste0(img_pth, "/", imgs[2])
processCore(image, last.year = last.year)
## [1] 2011
# GDrive folder "Rotelle_scansione": https://drive.google.com/drive/folders/1qr3ijH7iC8-BcueIO3l0VSkGWTk58U9a
img_dir <- "G:\\Il mio Drive\\DocumentiGDuniss\\02-RICERCA\\2017_Arzana-pineta\\Rotelle_scansione\\Cores\\"
last.year <- 2018
(imgs <- dir(img_dir))
## [1] "67-6-1.tif" "desktop.ini"
image <- paste0(img_dir, "67-6-1.tif")
str(tiff::readTIFF(image))
## num [1:1256, 1:2288, 1:3] 1 1 1 1 1 1 1 1 1 1 ...
processCore(image, last.year = last.year)
## [1] 2018