I intend to write a program that reads an image and adjusts the gamma value. I'm looping because I want to change the gamma from 0.6 to 0.9. However, when it is 0.6, it is executed, but after 0.7, it does not loop and an error occurs.
When I loaded the image and fixed the gamma value without looping, it worked, but after looping it, I couldn't. Thank you.
Since I am a beginner in the program, I think there are some points that I cannot reach, but thank you.
Corresponding source code
0.6 0.7 Traceback (most recent call last): File "d:/～～～ /change.py", line 40, in<module> im_1 = 255.0 * (picture/255.0) ** (1/gamma) TypeError: unsupported operand type (s) for /:'Image' and'float'
import cv2 import numpy as np import glob import os.path import os from PIL import Image import matplotlib.pyplot as plt (Path name omitted) f = open (new_annotation_txt, mode ='w') f.close () with open (picture_name_pass, encoding ='utf-8!') As picture_name_data: i = 0 for line in picture_name_data: picture_pass0 = line.replace ('\ n','') # picture_pass1 = picture_pass0 + ".jpg" picture = np.array (Image.open (picture_pass0), dtype ='float16') #Gamma correction gamma = 6/10 while gamma<1.0:<-Problem print (gamma) im_1 = 255.0 * (picture/255.0) ** (1/gamma) im_2 = 255.0 * (picture/255.0) ** gamma picture = Image.fromarray (np.uint8 (im_1)) #save_pass = picture_pass0 + ".jpg" save_pass = savepoint_pass + str (gamma) + "/" + Picture_pass0.replace (picture_pass,'') picture.save (save_pass) picture = Image.fromarray (np.uint8 (im_2)) save_pass = picture_pass0 + ".jpg" save_pass = savepoint_pass + "1_" + str (gamma) + "/" + Picture_pass0.replace (picture_pass,'') picture.save (save_pass) gamma + = 1/10 i + = 1 print (i) picture.close ()
Answer # 1
The picture before entering while is np.array, but it may be because the picture is updated with Image.fromarray in while and becomes an Image object.
Answer # 2
Excerpt from the problem
gamma_list = [0.6,0.7,0.8,0.9] When<-gamma + = 0.1, it became 0.7999999, so for the time being
num = 0
pic = picture
<-If the picture is rewritten, it cannot be used even if the original image is looped, so it is assigned to another variable.
gamma = gamma_list [num]
im_1 = 255.0 * (pic/255.0)(1/float (format (gamma,'.1f'))) im_2 = 255.0 * (pic/255.0)float (format (gamma,'.1 f'))
pic = Image.fromarray (np.uint8 (im_1))
save_pass = savepoint_pass + str (format (gamma,'.1f')) + "/"
+ picture_pass0.replace (picture_pass,'')
- python - i want to switch images using itemconfig in the gui, but it doesn't work
- python 3x - i want to set a response type bot that sends messages and images to discord with google colaboratory
- python - how to sort a 3d array
- python 3x - i want to get the nth array with an argument using python3 argparse
- display images by drag and drop on wxpython gui
- i want to manipulate the strings inside a python array
- python - i want to store an object in an array
- how to use python 2d array
- python - i want to download images from flickr
- python - i want to resolve typeerror: expected ptr for argument'% s'in cv2countnonzero
- python - i want to restore the result of calculating the inner product with numpy
- python - i want to move images with pygame
- python - i want to swap the first half and the second half of the array and put them in different arrays
- how to automate tweets with images from spython with json files
- python - handling of 1d array data when using the predict function in keras
- i want to click and number a few images like a switch in python
- parameters - about error when calculating python sarimx parameter optimization
- python - typeerror: can't multiply sequence by non-int of type'list'
- i want to make a python array one-dimensional, but it doesn't work
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- i want to call a child component method from a parent in vuejs
- python 3x - typeerror: 'method' object is not subscriptable
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- xcode - pod install [!] no `podfile 'found in the project directory