将元组从函数导入列表
Importing a tuple to a list from a function
我正在尝试在循环中使用范围修改像素,但我无法从大小函数导入范围。
load = bnw.load()
loadpx = [
(a),
(b)
]
bnw.size(loadpx)
print(loadpx)
for x in a:
for y in b:
new = load[x,y] + 10
if new > 254:
new = 254
bnw = new
bnw.size 的输出应该是图像的像素数。 (1920,1080)。在知道大小 a 被输入到 x 和 b 到 y 之后。
第一个答案的完整代码返回相同的错误
import tkinter as tk
import random
import os
import time
from tkinter import filedialog
from PIL import Image
import numpy as np
main_window = tk.Tk()
main_window.title("foto epic")
judul = tk.Label(main_window, text=" Editor Instagram epic 2 BnW Edition wkwk \n\n Silahkan Input foto Dibawah\n\/\n")
judul.pack()
def UploadAction():
file = filedialog.askopenfilename()
print('Selected:', file)
img = Image.open(file)
bnw2 = img.convert(mode = "L")
print(bnw2.size)
load = bnw2.load()
r,c = bnw2.size()
for x in range(r):
for y in range(c):
new = load[x,y] + 10
if new > 254:
new = 254
new = bnw2
arraying = np.asarray(bnw2)
counting = np.bincount(arraying.flatten(), minlength = 128)
px_num = np.sum(counting)
counting = counting/px_num
sum1 = np.cumsum(counting)
floorcount = np.floor(255 * sum1).astype(np.uint8)
donecount = list(arraying.flatten())
transforming = [floorcount[p] for p in donecount]
transforming = np.reshape(np.asarray(transforming), arraying.shape)
done_transform = Image.fromarray(transforming)
done = tk.Label(main_window, text=" \nFoto Telah di export!\nTerimakasih Sudah Menggunakan Program ini!\n")
done.pack()
done_transform.show()
if os.path.exists('result.jpg'):
done_transform.save('result_{}.jpg'.format(int(time.time())))
else:
done_transform.save('result.jpg')
button = tk.Button(main_window, text='Beautify!', command=UploadAction)
button.pack()
tk.mainloop()
我用的是Tkinter UI不知道会不会影响原题
错误
Selected: D:/Code/Kuliah/Semester 3/citra/yes/DSC_3044.jpg
(4608, 1975) < the resolution if printed
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "d:\Code\Kuliah\Semester 3\citra\yes\Tugas Pengolahan Citra.py", line 22, in UploadAction
r,c = bnw2.size()
TypeError: 'tuple' object is not callable
我在这里编辑了现在应该可以使用的答案:
file = filedialog.askopenfilename()
print('Selected:', file)
img = Image.open(file)
bnw2 = img.convert(mode = "L")
load = bnw2.load()
r,c = bnw2.size
for x in range(r):
for y in range(c):
new = load[x,y] + 10
if new > 254:
new = 254
load[x,y] = new
我正在尝试在循环中使用范围修改像素,但我无法从大小函数导入范围。
load = bnw.load()
loadpx = [
(a),
(b)
]
bnw.size(loadpx)
print(loadpx)
for x in a:
for y in b:
new = load[x,y] + 10
if new > 254:
new = 254
bnw = new
bnw.size 的输出应该是图像的像素数。 (1920,1080)。在知道大小 a 被输入到 x 和 b 到 y 之后。
第一个答案的完整代码返回相同的错误
import tkinter as tk
import random
import os
import time
from tkinter import filedialog
from PIL import Image
import numpy as np
main_window = tk.Tk()
main_window.title("foto epic")
judul = tk.Label(main_window, text=" Editor Instagram epic 2 BnW Edition wkwk \n\n Silahkan Input foto Dibawah\n\/\n")
judul.pack()
def UploadAction():
file = filedialog.askopenfilename()
print('Selected:', file)
img = Image.open(file)
bnw2 = img.convert(mode = "L")
print(bnw2.size)
load = bnw2.load()
r,c = bnw2.size()
for x in range(r):
for y in range(c):
new = load[x,y] + 10
if new > 254:
new = 254
new = bnw2
arraying = np.asarray(bnw2)
counting = np.bincount(arraying.flatten(), minlength = 128)
px_num = np.sum(counting)
counting = counting/px_num
sum1 = np.cumsum(counting)
floorcount = np.floor(255 * sum1).astype(np.uint8)
donecount = list(arraying.flatten())
transforming = [floorcount[p] for p in donecount]
transforming = np.reshape(np.asarray(transforming), arraying.shape)
done_transform = Image.fromarray(transforming)
done = tk.Label(main_window, text=" \nFoto Telah di export!\nTerimakasih Sudah Menggunakan Program ini!\n")
done.pack()
done_transform.show()
if os.path.exists('result.jpg'):
done_transform.save('result_{}.jpg'.format(int(time.time())))
else:
done_transform.save('result.jpg')
button = tk.Button(main_window, text='Beautify!', command=UploadAction)
button.pack()
tk.mainloop()
我用的是Tkinter UI不知道会不会影响原题
错误
Selected: D:/Code/Kuliah/Semester 3/citra/yes/DSC_3044.jpg
(4608, 1975) < the resolution if printed
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "d:\Code\Kuliah\Semester 3\citra\yes\Tugas Pengolahan Citra.py", line 22, in UploadAction
r,c = bnw2.size()
TypeError: 'tuple' object is not callable
我在这里编辑了现在应该可以使用的答案:
file = filedialog.askopenfilename()
print('Selected:', file)
img = Image.open(file)
bnw2 = img.convert(mode = "L")
load = bnw2.load()
r,c = bnw2.size
for x in range(r):
for y in range(c):
new = load[x,y] + 10
if new > 254:
new = 254
load[x,y] = new