1

I want to convert image (.jpg) to binary array. Because I have to use this array to my scrambler operating on it saved in file. Which library and and functions should I use?

4
  • Check out this link: stackoverflow.com/questions/13550376/… Commented Apr 16, 2018 at 23:39
  • 1
    Possible duplicate of PIL image to array (numpy array to array) - Python Commented Apr 16, 2018 at 23:44
  • OP mentioned in a comment that he's using Python 3.6.4, so PIL won't actually help him, and I'm guessing that he'll need a Python 3 alternative. Commented Apr 17, 2018 at 0:14
  • @ZeBirdeh Hopefully he's going to incorporate that information into the post because, as it stands, the question needs work. Commented Apr 17, 2018 at 0:49

3 Answers 3

1

You should take a look at the openCV library.

import cv2
img = cv2.imread('image.jpg', flags=cv2.IMREAD_COLOR)
Sign up to request clarification or add additional context in comments.

2 Comments

ModuleNotFoundError: No module named 'cv2' || I can't use cv2, there is no option to import it. I have Python3.6.4
You should install the opencv module first for this to work. pypi.org/project/opencv-python
1

You can use the python library: PIL & numpy. Click here to learn more about image handling in python.

import numpy
import PIL

img = PIL.Image.open("foo.jpg").convert("L")
imgarr = numpy.array(img)

Comments

0
  • You can use this code to convert your image to array
# Import the necessary libraries 
from PIL import Image 
from numpy import asarray 
  
  
# load the image and convert into  
# numpy array 
img = Image.open('test.jpg') 
arraydata = asarray(img) 
  
# data 
print(arraydata) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.