Image processing using Keras in R


#1

Hello

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.
cat

R Code:

image1_resize=image_load("Cat.jpg",grayscale=TRUE,target_size = c(100,110))
resize_array1=image_to_array(image1_resize)
image(matrix(resize_array1),col=grey.colors(255))

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?


#2

Try this instead:

# Download a cat image
cat <- "https://upload.wikimedia.org/wikipedia/commons/b/bb/Kittyply_edit1.jpg"
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) %>%
  plot()

image


#3

Thanks a lot.

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


#4

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