Code Monkey home page Code Monkey logo

Comments (4)

alsuhr-c avatar alsuhr-c commented on August 27, 2024

What software are you using to view 4 channels? Is this CMYK? You should be able to interpret the images as 3-channel (RGB).

from nlvr.

AashishV avatar AashishV commented on August 27, 2024
from PIL import Image
import numpy as np

img_filename = '../../../Dataset/nlvr/train/images/1/train-1196-0-0.png'

img = Image.open(img_filename)
print(np.array(img).shape)

This gives an output as (100, 400, 4).

So, I am using the below snippet:

from PIL import Image
import numpy as np

img_filename = '../../../Dataset/nlvr/train/images/1/train-1196-0-0.png'

img = Image.open(img_filename).convert('RGB')
print(np.array(img).shape)

This gives me an output of (100, 400, 3) but I have to divide them by 255 to make the values lie in between 0 and 1.

from nlvr.

alsuhr-c avatar alsuhr-c commented on August 27, 2024

I'm not very familiar with PIL, and in our code we use scipy imread (which calls PIL and gives us four channels -- we throw away the last channel). The last channel value is 255 for us, so I would guess this is some kind of alpha value. I'd suggest ignoring this channel because the values are all the same for each example. I'd also suggest dividing by 255. But you can investigate with PIL to see if it can do all of this by default for you. Does this answer your question?

from nlvr.

AashishV avatar AashishV commented on August 27, 2024

Yes, this does answer my question. Thank you for the quick reply.

from nlvr.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.