#python #image #function
Вопрос:
Итак, я получал эту ошибку, и я пробовал так много других вещей, мне было интересно, знает ли кто-нибудь, как я мог бы это исправить? Я приведу здесь весь свой код.
import random #importing libraries
import urllib.request
print("This system is for downloading url images from the internet on to your files/computer")
def yes(): #defining the function yes to get a url image
foo = input("Would you like to download an image from a different browser to your files? ENTER YES or NO: ")
if foo == ("YES"):
def down_load_imag(url):
name = random.randrange(1, 1000)
full_name = str(name) ".jpg"
urllib.request.urlretrieve(url, full_name)
url = input('Enter url pleass open image in a new tab then use that website url: ')
# here you can evaluate url with regex and if passed:
down_load_imag (url)
Nextstep()
else:
print('Image Couldn't be retreived')
yes()
def Nextstep(): #asking if it would like to zoom into the page remember the user has to first name the file they would like and then add to code
foo = input ("Would you like to zoom into the image, if yes enter K if no then you can click on your new image that was downoloaded to your files: ")
if foo == ("K"):
inputvalue() #allowing user to decide if they would like to explore the images further if not then their image is in their files folder if yes continues with the code
else:
print('that is not a valid option')
Nextstep()
#this resizes your image into 4 different ways
def inputvalue(): #still trying to find a way to take in an input where the user submites its image that it would lile to download and zoom into#update this os working
zoo = input('Enter the name of the file that was saved to your files in the previous step: ')
doublechecking()
def doublechecking():
foo = input ("Are you ready for the next step? enter 'L' for yes if not make sure youre ready ")
if foo == ("L"):
import os
import sys
import numpy as np
from scipy.interpolate import griddata
import matplotlib.pyplot as plt
from PIL import Image
import random
def make_interpolated_image(nsamples):
"""Make an interpolated image from a random selection of pixels.
Take nsamples random pixels from im and reconstruct the image using
scipy.interpolate.griddata.
"""
ix = np.random.randint(im.shape[1], size=nsamples)
iy = np.random.randint(im.shape[0], size=nsamples)
samples = im[iy,ix]
int_im = griddata((iy, ix), samples, (Y, X))
return int_im
# Read in image and convert to greyscale array object
img_name = sys.argv[1]
name = inputvalue
im = Image.open(name) #user has to download image from web first make sure the image is here in the code so it can read it
#on to the files of the user
im = np.array(im.convert('L'))
# A meshgrid of pixel coordinates
nx, ny = im.shape[1], im.shape[0]
X, Y = np.meshgrid(np.arange(0, nx, 1), np.arange(0, ny, 1))
# Create a figure of nrows x ncols subplots, and orient it appropriately
# for the aspect ratio of the image.
nrows, ncols = 2, 2
fig, ax = plt.subplots(nrows=2, ncols=2, figsize=(6,4), dpi=100)
if nx < ny:
w, h = fig.get_figwidth(), fig.get_figheight()
fig.set_figwidth(h), fig.set_figheight(w)
# Convert an integer i to coordinates in the ax array
get_indices = lambda i: (i // nrows, i % ncols)
# Sample 100, 1,000, 10,000 and 100,000 points and plot the interpolated
# images in the figure
for i in range(4):
nsamples = 10**(i 2)
axes = ax[get_indices(i)]
axes.imshow(make_interpolated_image(nsamples),
cmap=plt.get_cmap('Greys_r'))
axes.set_xticks([])
axes.set_yticks([])
axes.set_title('nsamples = {0:d}'.format(nsamples))
filestem = os.path.splitext(os.path.basename(img_name))[0]
plt.savefig('{0:s}_interp.png'.format(filestem), dpi=100) #saving the image to files
Комментарии:
1. Вы забыли
()
вызвать функцию здесь:name = inputvalue
2. Пожалуйста, попробуйте следовать учебнику, изучить основы и ознакомиться с правильным стилем, прежде чем пытаться писать свои собственные программы с использованием сторонних библиотек. Код, который вы показываете здесь, предполагает много копирования и вставки и не очень много размышлений. Достоверно написать правильный код можно только в том случае, если вы понимаете, что вы пишете, как вы это пишете.