-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creating a .ppm
file under bitmap()
fails under Window's GhostScript
#1
Comments
Options: New backendSwitch to using e.g. # Create a temporary file path using a known directory
temp_dir <- tempdir()
temp_file <- tempfile(tmpdir = temp_dir, fileext = ".png")
# Create a bitmap image
png(temp_file, antialias="none")
# Create a blank plot
plot(1, 1, type = "n", axes = FALSE, xlab = "", ylab = "")
# Add text to the plot
text(1, 1, "Testing print", cex = 4)
# Close the plotting device
dev.off()
# Read the image file
image <- png::readPNG(temp_file)
# Convert the array to integer values between 0 and 255
img_matrix <- round(image[,,3] * 255)
size <- dim(img_matrix)
# Display the image
head(img_matrix)
image(img_matrix)
# Create a data frame of non-white points
non_white_points <- which(img_matrix == 0, arr.ind = TRUE)
df <- data.frame(
x = non_white_points[, 2], # Column index represents x
y = nrow(img_matrix) - non_white_points[, 1] + 1 # Row index represents y, but flipped
)
plot(df) Hard requirementAdd to
https://github.com/cran/grImport/blob/2c54f79cde111005659229ec7b22b5c124776654/DESCRIPTION#L5 Detection on ghostwriter vs. OSNeed to modify/incorporate a function (gsexe, type)
{
gshelp <- system(paste(gsexe, "-help"), intern = TRUE)
st <- grep("^Available", gshelp)
en <- grep("^Search", gshelp)
if (!length(st) || !length(en))
warning("unrecognized format of gs -help")
else {
gsdevs <- gshelp[(st + 1L):(en - 1L)]
devs <- c(strsplit(gsdevs, " "), recursive = TRUE)
if (match(type, devs, 0L) == 0L) {
op <- options(warning.length = 8000L)
on.exit(options(op))
stop(gettextf("device '%s' is not available\n", type),
gettextf("Available devices are:\n%s", paste(gsdevs,
collapse = "\n")), domain = NA)
}
}
} |
Maybe also include a conversion across the cube over to greyscale instead of just one dimension (since # Convert the array to integer values between 0 and 255
img_matrix <- round(image * 255)
img_grey_matrix <- apply(image, c(1, 2), sum)
img_grey_matrix <- img_grey_matrix/max(img_grey_matrix)
img_grey_matrix <- round(img_grey_matrix*255) |
Change image parsing to search all channels of the array. Close #1
See PPM spec: https://paulbourke.net/dataformats/ppm/
Ideal output (need to delete first 4 lines/header)
Windows output:
MWE:
For whatever reason, the device of
ppm
on Windows is not being detected across the test suites I have access to. So, we'll disablesurreal_text()
on non-unix platforms.The text was updated successfully, but these errors were encountered: