Image processing using Keras in R


I have imported an image as a grey scale image and then resized it using Keras package in R, but when I plotted it using image() function in R, I am getting below plot.

R Code:

image1_resize=image_load("Cat.jpg",grayscale=TRUE,target_size = c(100,110))

In python I have red the image as grey scale using cv2 library and when I plot, getting desired result as belowcatp
Any specific reason for this?

Try this instead:

# Download a cat image
cat <- ""
cat_file <- tempfile(fileext = ".jpg")
download.file(cat, destfile = cat_file, mode = "wb")
# Plot the image

image_load(cat_file, grayscale = TRUE, target_size = c(100, 100)) %>% 
  image_to_array() %>%
  array_reshape(dim = c(dim(.)[1:2])) %>%
  as.raster(max = 255L) %>%


1 Like

Thanks a lot.

So we need to convert the array as raster then plot.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.