Sort AFM Images
tutorial
AFM
code
Sorting AFM images quickly from RStudio
This code helps you sort AFM images and categorize them into high- and low-quality images for analysis later on. You can run this code within RStudio. Make sure that the nanoAFMr
package is installed. The user is prompted for a path that contains AFM images, then each AFM image is displayed and the user can rate it high
, medium
or low
according to its quality.
The result is saved in out.csv
file.
library(nanoAFMr)
= NULL
p while(is.null(p)) {
cat("Please enter the file path with AFM image (searches recursively: ")
# Read the user input
<- readline()
p if(!dir.exists(p)) p=NULL
}
= c(dir(p, pattern="tiff$", full.names = TRUE, recursive = TRUE),
file_list dir(p, pattern = "ibw$", full.names = TRUE, recursive = TRUE),
dir(p, pattern = "nid$", full.names = TRUE, recursive = TRUE))
cat("Found",length(file_list),"AFM files.\n\n")
cat("Enter Q to quit.\n\n")
=data.frame()
rfor(f in file_list) {
= AFM.import(f)
a print(a)
<- AFM.flatten(a)
a print(plot(a))
cat("Enter rating (Q=quit, 1=high,2=mid,3=low:")
<- readline()
rating if(rating=="q" || rating=="Q") break
= as.numeric(rating)
rating
# set default rating if needed
if (is.na(rating) || rating == "") rating <- 3
= rbind(r,
r data.frame(
filename = f,
rating = rating
))
}write.csv(r, "out.csv", row.names = FALSE)
cat("Ratings saved in file out.csv and variable r.\n")
Citation
BibTeX citation:
@misc{gredig2024,
author = {Gredig, Thomas and Gredig, Thomas},
title = {Sort {AFM} {Images}},
date = {2024-11-20},
url = {https://www.csulb.edu/~tgredig/posts/sortAFM_images/sortAFM_images.html},
langid = {en}
}
For attribution, please cite this work as:
Gredig, Thomas, and Thomas Gredig. 2024. “Sort AFM Images.”
https://www.csulb.edu/~tgredig/posts/sortAFM_images/sortAFM_images.html.