Search
Question: Not able to display actual grayscale image using EBImage
1
gravatar for Kpurva
19 months ago by
Kpurva10
Germany
Kpurva10 wrote:

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.

Binary image generated using EBImage package

ADD COMMENTlink modified 19 months ago by Andrzej Oleś670 • written 19 months ago by Kpurva10
2
gravatar for Andrzej Oleś
19 months ago by
Andrzej Oleś670
EMBL Heidelberg, Germany
Andrzej Oleś670 wrote:

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 COMMENTlink modified 19 months ago • written 19 months ago by Andrzej Oleś670
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.2.0
Traffic: 314 users visited in the last hour