library(jpeg) # For reading JPEG images
library(tibble) # For creating data frames
library(dplyr) # For data manipulation
library(ggplot2) # For plotting
# Create a dummy image for demonstration if actual image is not present
# In a real scenario, you'd replace this with your actual image path
if (!file.exists("images/JODAVID.jpg")) {
message("images/JODAVID.jpg not found. Creating a dummy image for demonstration.")
# Create a simple image data (e.g., 50x50, 3 channels)
dummy_image_data <- array(runif(50*50*3), dim = c(50, 50, 3))
# Create the directory if it doesn't exist
if (!dir.exists("Figures")) {
dir.create("Figures")
}
# Save a simple JPEG image
writeJPEG(dummy_image_data, "images/JODAVID.jpg")
}
# Read the image
imagem <- readJPEG("images/JODAVID.jpg")
# Organize the image into a data frame (long format)
# Each row represents a pixel with its (X,Y) coordinates and RGB values
imagemRGB <- tibble(
X = rep(1:dim(imagem)[2], each = dim(imagem)[1]),
Y = rep(dim(imagem)[1]:1, dim(imagem)[2]), # Y-axis inverted for plotting
R = as.vector(imagem[,,1]),
G = as.vector(imagem[,,2]),
B = as.vector(imagem[,,3])
)

















