Re: python users please save me

Hi there,
@1: hmm, under the term focus something, we usually understand moving the keyboard focus to a particular place in the environment. This is quite rarely done outside your own app, so I guess you probably meaned something else?

As for getting width and height of a particular image, well, this is not that simple. An image is a bunch of bytes, which you need to decode first to a matrix of pixels i.e. three dimensional array in order to work with it. As you wrote, that you're just starting in Python, make sure you know this concept, as doing this stuff without it is... kind of difficult. smile
Then, you most likely don't want to write your own JpG decoder, as there is plenty of them already available and it would be a waste of time. My favorite is ImageIO. You can install it along numpy like:

pip install numpy imageio

You can then load an image into a numpy array like so:

import numpy as np
from imageio import imread

image=np.asarray(imread("image.jpg"))
print(f"Dymensions of the image are {image.shape}")

Here image.shape returns a tuple containing array dymensions i.e. if the array is 3D, it will contain three items, usually x, y and 3.
Now, the question is, which of the two first elements is width and whichone height.
If I remember right, the firstone was height and secondone width, but I recommend checking it out either in imageio's documentation or by comparing with a viewer, i've worked with few libraries for handling images including ImageIO, PIL and OpenCV, and they use various formats for this.

PIL and OpenCV also have various functions for shifting, rotating, zooming and other functions, which you may be interested in. There are plenty of tutorials especially for OpenCV, btw the loading syntax is very similar to thatone of ImageIO.
Also note that the sample above decompresses and loads the whole image to memory, as finding its shape is usually not the only thing you want to do. There are also cases when however it's the only required information, and you don't need to load the whole thing in that case. OpenCV has a function to get the dimensions only, so you can use it as well when necessary.

Best regards

Rastislav



-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : Meatbag via Audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : Turkce_Rap via Audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : Blue-Eyed Demon via Audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : Rastislav Kish via Audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : Rastislav Kish via Audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : Rastislav Kish via Audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : Rastislav Kish via Audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : magurp244 via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Rastislav Kish via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Meatbag via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : cartertemm via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Turkce_Rap via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Blue-Eyed Demon via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Rastislav Kish via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector

Reply via email to