Not able to display actual grayscale image using EBImage
1
1
Entering edit mode
Kpurva ▴ 10
@kpurva-10058
Last seen 5.6 years ago
Germany

I am using the EBImage package for image processing in R. I have a 260 by 134 Matrix which I converted to an image using

    > image1 <- as.Image(matrix1)

And, here is the image object summary

    > image1
colorMode    : Grayscale
storage.mode : double
dim          : 260 134
frames.total : 1
frames.render: 1

imageData(object)[1:5,1:6]
[,1] [,2] [,3] [,4] [,5] [,6]
[1,]    0    0    0    0    0    0
[2,]    0    0    0    0    0    0
[3,]    0    0    0    0    0    0
[4,]    0    0    0    0    0    0
[5,]    0    0    0    0    0    0

A value greater than zero for a specific cell in the image object looks like this:

   > imageData(image1)[9,2]
[1] 3686.308

I then use the display function in the EBImage package to view the image which is build from the matrix data.

    > display(image1, method = "raster")

However, I get a binary image i.e just black and white pixels. I have shown it below. My data does not just consist of 0 and 1. The background values are zero but the regions with the actual image pattern have values higher than 1. How do I display the image using grayscale and using the functions in this package? Did someone face a similar issue? I also could not find a parameter to specify a gradient level.

ebimage image processing image display • 1.3k views
ADD COMMENT
2
Entering edit mode
Andrzej Oleś ▴ 750
@andrzej-oles-5540
Last seen 18 months ago
Heidelberg, Germany

The reason why the image renders only as black and white is because the display function expects values in the range [0, 1]. Values higher than 1 are clipped and effectively display as 1 (white).

To properly visualize your data you first need to scale the pixel intensity values to the [0, 1] range. This can be done with the help of the normalize function:

image1 <- normalize(image1)
display(image1, method = "raster")
ADD COMMENT

Login before adding your answer.

Traffic: 376 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6