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.
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 below
Any specific reason for this?
andrie
September 18, 2018, 1:31pm
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()
1 Like
Thanks a lot.
So we need to convert the array as raster then plot.
system
Closed
November 10, 2018, 7:57am
4
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.