第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何生成結(jié)果作為圖形標(biāo)題以及與繪制圖像相關(guān)的文件名?

如何生成結(jié)果作為圖形標(biāo)題以及與繪制圖像相關(guān)的文件名?

胡子哥哥 2024-01-04 15:22:56
我需要幫助,將測試結(jié)果和文件名放在一起作為評(píng)估圖像的標(biāo)題。我可以將測試結(jié)果生成為列表(參見圖片),我可以將測試結(jié)果添加到圖像上。我可以將文件名添加到圖像頂部。但是,我不能兩者兼得。不確定我做錯(cuò)了什么。謝謝。path = '/Users/minny/Desktop/A/png/file2/'ref_images = glob.iglob(path + "*.png")  all_ref_images = []  for ref_path in ref_images:      ref_head, tail = os.path.splitext(ref_path)     image1 = Image.open(ref_path)     imgA= print(calculate_brightness(image1))    #all_ref_images.append([imgA, ref_head])        ref_image = plt.imshow(image1)    fig = plt.figure()            plt.title(os.path.basename(ref_head)), plt.title(calculate_brightness(image1))            #plt.axis("off")def calculate_brightness(image):greyscale_image = image.convert('L')histogram = greyscale_image.histogram()pixels = sum(histogram)brightness = scale = len(histogram)for index in range(0, scale):    ratio = histogram[index] / pixels    brightness += ratio * (-scale + index)return 1 if brightness == 255 else brightness / scale%%capture #gives a standard size image to view inline with the text def display_img(img, cmap=None):     fig = plt.figure(figsize=(3,3))     ax = fig.add_subplot(111)     ax.imshow(img, cmap)  path = '/Users/minny/Desktop/A/png/file2/' ref_images = glob.iglob(path + "*.png")   all_ref_images = []  for ref_path in ref_images:      ref_head, tail = os.path.splitext(ref_path)     image1 = Image.open(ref_path)     imgA= print(calculate_brightness(image1))    all_ref_images.append([imgB, ref_head])                   fig = plt.figure()          ref_image = plt.imshow(image1)    print(os.path.basename(ref_head))            #plt.axis("off")    ref_image = plt.imshow(image1)    image_basename = os.path.basename(ref_head)    title = '\n'.join([image_basename, str(calculate_brightness(image1))])    plt.title(title, loc='left')    dir_name = '/Users/minny/Desktop/A/png/results/'    plt.savefig('{dir_name}/{filename}'.format(dir_name=dir_name, filename=image_basename))
查看完整描述

1 回答

?
慕標(biāo)5832272

TA貢獻(xiàn)1966條經(jīng)驗(yàn) 獲得超4個(gè)贊

您可以將圖像路徑的基本名稱與calculate_brightness函數(shù)的輸出連接起來,并將結(jié)果設(shè)置為標(biāo)題而不覆蓋它們:


ref_image = plt.imshow(image1)

image_basename = os.path.basename(ref_head)

test_results = '\n'.join(map(str, calculate_brightness(image1)))

title = '\n'.join([image_basename, test_results])

plt.title(title, loc='left')

UPD:如果calculate_brightness函數(shù)的結(jié)果是浮點(diǎn)數(shù),你可以通過這種方式解決你的問題:


ref_image = plt.imshow(image1)

image_basename = os.path.basename(ref_head)

title = '\n'.join([image_basename, str(calculate_brightness(image1))])

plt.title(title, loc='left')

UPD2: 要將圖像保存到指定文件夾,您可以使用 plt.savefig 方法:


dir_name = '/Users/minny/Desktop/A/png/file2/some_directory' # create directory if necessary

plt.savefig('{dir_name}/{filename}'.format(dir_name=dir_name, filename=image_basename))



查看完整回答
反對(duì) 回復(fù) 2024-01-04
  • 1 回答
  • 0 關(guān)注
  • 129 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)