Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating binary RGB values from image in python results in wrong size

Tags:

python

opencv

I am trying to extract binary values for red, green and blue from an image in python using OpenCV. The image has the size 224x224. I separate the values like this:

img = cv2.imread('image.jpg')
img = cv2.resize(img, (224, 224))
b,g,r = cv2.split(img)

But when I print out the size of one color value with print(sys.getsizeof(r)), I get a result of 50288, even if 224x244 should be 50176.

There must be some overhead, does anyone know how I get values for the 50176 pixels?

I want to store the image values with classifier as binary file like this: 1 byte classifier + 50176 red values + 50176 green values + 50176 blue values

like image 384
ArnoXf Avatar asked Mar 07 '26 03:03

ArnoXf


1 Answers

img = cv2.imread('image.jpg') returns a numpy array, which is in general the object type used by opencv to store images. Numpy array introduces indeed some overhead which causes the size of the object to be bigger than just the array buffer.

To check the size of the buffer, you can call for example img.nbytes.

like image 104
Antonio Avatar answered Mar 08 '26 16:03

Antonio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!