Set of functions which may be helpful for image manipulation prior to training a deep learning algorithm.
install using:
library(devtools)
install_github("amanasj/imageAIready")
library(imageAIready)
############################
############################
################################################
#devtools::install_github("amanasj/imageAIready", force=T)
library(imageAIready)
library(readheyexxml)
library(keras)
################################################
##############################################################
patient_folder <- ""
timepoint <- ""
eye <- "OD"
###############################
filepath <- paste0("", patient_folder,"\\",timepoint)
### file path for OD or OS images
images_path <- file.path(paste0(filepath,"\\",eye))
#############################################################
-------------------------------------------------------------
##########################################################
readheyexxml <- readheyexxml(images_path)
#readheyexxml[3]
#####################################################
#################################
resize <- imageAIready::resize(images_path, width = 1024, height = 512, destin = dirname(images_path))
##########################################################
###########################################################################
bbox <- imageAIready::bbox_crop(images_path = images_path, width = 1024, height = 512, heyex_xml_file = T, destin = dirname(images_path))
############################################################################
##########################################
bbox_images_folder <- paste0(filepath, "\\bboxcropped_images\\",eye,"\\cropped_images\\images\\")
patches <- imageAIready::patchifyR(images_path = bbox_images_folder, patch_size = 256, heyex_xml_file = F, destin = dirname(bbox_images_folder))
###################################################################
#################################
bbox_images_folder <- paste0(filepath, "\\bboxcropped_images\\",eye,"\\cropped_images\\image_patches\\images\\")
images <- imageseg::loadImages(bbox_images_folder)
images <- imageseg::imagesToKerasInput(images, type = "image", grayscale = F)
model <- keras::load_model_hdf5("", compile = F)
(NOTE: imageSegementation from imageseg package not working for me, so edited package by adding .ragged=TRUE and saved new function as v2)
predictions <- imageAIready::imageSegmentation_v2(model=model, x=images, threshold = 0.9)
#####################################################################
######################################################################################
images_folder <- paste0(filepath, "\\bboxcropped_images\\",eye,"\\cropped_images\\image_patches\\images\\")
ORT <- imageAIready::predictions_overlay(images_folder=images_folder, predictions=predictions, destin = dirname(dirname(images_folder)))
#######################################################################################
##################################################
patches_folder <- paste0(filepath,"/bboxcropped_images/",eye,"/cropped_images/AI_predictions/patches/")
mosaic <- imageAIready::mosaicR(patches_folder = patches_folder)
#######################################################
##############################################################
heyex_images_folder <- file.path(paste0(filepath,"\\",eye))
bbox_full_images_folder <- paste0(filepath, "\\bboxcropped_images\\",eye,"\\cropped_images\\images\\")
ORT_data_F <- imageAIready::findORT(predictions, heyex_images_folder = heyex_images_folder, bbox_full_images_folder = bbox_full_images_folder, ORT_size_min = 200)
save(ORT_data_F, file = paste0(heyex_images_folder, "//ORT_data_F.Rdata"))
#################################################################
#####################################################
heyex_images_folder <- file.path(paste0(filepath,"\\",eye))
enfaceORTplot <- imageAIready::enfaceORTplot(ORT_coords = ORT_data_F[[1]], heyex_images_folder = heyex_images_folder)
######################################################
################################################
root <- dirname(images_path)
unlink(file.path(paste0(root,"/bboxcropped_images/")), recursive = T)
unlink(file.path(paste0(root,"/resized_images/")), recursive = T)
#####################################################