subsetdata$image [1] "images/470blur80.jpg" "images/440contrast70.jpg"…
- User
subset_data$image [1] "images/470_blur_80.jpg" "images/440_contrast_70.jpg" "images/382_contrast_90.jpg" "images/9_jpeg_80.jpg" "images/288_jpeg_80.jpg" "images/115_contrast_70.jpg" "images/113_contrast_70.jpg" "images/228_contrast_70.jpg" "images/180_contrast_90.jpg" "images/227_contrast_90.jpg" [11] "images/467_blur_80.jpg" "images/100_jpeg_70.jpg" "images/147_contrast_70.jpg" "images/216_contrast_70.jpg" "images/469_jpeg_70.jpg" "images/277_contrast_90.jpg" "images/536_jpeg_70.jpg" "images/39_original.jpg" "images/65_jpeg_80.jpg" "images/396_jpeg_70.jpg"
[21] "images/475_jpeg_80.jpg" "images/345_blur_70.jpg" "images/51_blur_80.jpg" "images/226_blur_70.jpg" "images/233_jpeg_90.jpg" "images/177_blur_70.jpg" "images/10_jpeg_80.jpg" "images/149_blur_90.jpg" "images/328_blur_70.jpg" "images/190_contrast_90.jpg"I have shown images either in their original state or with "jpeg", "blur" or "contrast" distortion. If the images are distorted the can be distorted at levels "70", "80 or "90" which represents how many percentage of the original quality they are expected to have (SSIM). How can I elegantly separate the image into its different category names using the image name? Also propose BRMS models to predict another variable called ratings from the nested combination of image distortions and levels. Here is a first attempt:
Find distortions and categories
Image number
subset_dataImageNumber <- gsub("^\\D*([0-9]+)_.*", "\1", subset_data$image)
Extract letters following the first underscore until a second underscore or ".jpg" is encountered
subset_datadistortion <- gsub("^[^_]+_(.*?)(_[^_]+\\.jpg|\\.jpg)", "\1", subset_data$image)
Extract last set of digits immediately followed by ".jpg" for each filename
subset_data", "\1", subset_data$image)
Convert cases that are not "70", "80", or "90" to "100"
subset_data", "\1", subset_datalevel[!subset_data$level %in% c("70", "80", "90")] <- "100"
- Assistant
Create new columns for the distortions and categories
subset_dataImageNumber <- as.integer(gsub("^\\D*([0-9]+)_.*", "\1", subset_datadistortion <- gsub("^[^]+([^]+)([^_]+\.jpg|\.jpg)image) subset_data", "\1", subset_datalevel[!subset_datalevel <- as.integer(subset_data$level)
Convert the new columns to factors
subset_datadistortion, levels = c("original", "jpeg", "blur", "contrast")) subset_datalevel, levels = c(100, 70, 80, 90))
Load required library
library(brms)
Propose a BRMS model to predict ratings from the nested combination of image distortions and levels
Model 1: Random intercepts for distortions and levels
model1 <- brm(ratings ~ (1 | distortion) + (1 | level), data = subset_data)
Model 2: Varying slopes for distortions within levels
model2 <- brm(ratings ~ (1 + distortion | level), data = subset_data)
Model 3: Varying slopes for levels within distortions
model3 <- brm(ratings ~ (1 + level | distortion), data = subset_data)
Compare models using loo (leave-one-out cross-validation) and select the best model
loo_scores <- loo(model1, model2, model3) best_model <- which.min(loo_scores$elpd)