【发布时间】:2021-05-20 18:01:15
【问题描述】:
我正在研究潜在指纹识别和分类系统。我在 colab 中对此进行了编码,其中代码运行良好,但是当我使用 UI 复制粘贴到 pycharm 时,它会输出黑色图像以用于侵蚀功能。
在我的代码中,图像增强后,我应用了腐蚀。下面显示的输出图像是我在colab上分别运行增强和腐蚀代码时得到的图像:
但是当我在 pycharm 上编码时:
norm, mask = __ridge_segment(img) # normalise the image and find a ROI
orient = __ridge_orient(norm) # compute orientation image
freq = __ridge_freq(norm, orient, mask) # compute major frequency of ridges
binim = __ridge_filter(norm, freq, img, orient) # filter the image using oriented gabor
filter
binim1 = Image.fromarray(binim)
with BytesIO() as output:
binim1.save(output, format="PNG")
binim1 = output.getvalue()
frame.update(data=binim1)
return binim
上面的代码在数组中输出带有布尔值的增强图像。
def Morph(out1,frame):
#out1 = np.array(out1)
out1=out1.copy()
out1 = np.array(out1).astype(np.uint8)
out1 = np.array(out1)
kernel = np.ones((2, 2), np.uint8)
kernel1 = np.ones((2, 2), np.uint8)
Erode = cv2.erode(out1, kernel, iterations=1)
Dilate = cv2.dilate(Erode, kernel1, iterations=1)
Morpho = Image.fromarray(Dilate)
sg.Popup('Ok clicked')
with BytesIO() as output:
Morpho.save(output, format="PNG")
Morpho = output.getvalue()
frame.update(data=Morpho)
if __name__ == '__main__':
sg.theme('Dark')
sg.set_options(font=('Courier New', 11))
w, h = size_of_image = (700, 600)
layout_top = [
[sg.InputText(enable_events=True, key='-FOLDER-'),
sg.FolderBrowse('Browse', size=(7, 1), enable_events=True)],
[sg.InputText(enable_events=True, key='-FILTER-'),
sg.Button('Search', size=(7, 1))],[sg.Listbox([], size=(45, 10), enable_events=True,
select_mode=sg.LISTBOX_SELECT_MODE_SINGLE, key='-LISTBOX-')],
]
layout_bottom = [
[sg.Button('Normalize', size=(20, 1),enable_events=True, key="normalize")],
[sg.Button('Enhance', size=(20, 1),enable_events=True,key="Enhance")],
[sg.Button('Morpholgy', size=(20, 1),enable_events=True,key='morph')],
[sg.Button('Binarization', size=(20, 1))], [sg.Button('Thinning', size=(20, 1))],
[sg.Button('Singular Points', size=(20, 1),enable_events=True, key= 'singular')],
[sg.Button('Minutiae', size=(20, 1))],
[sg.Button('Classify', size=(20, 1))], [sg.Button('Match', size=(20, 1))],
]
layout_left = [
[sg.Column(layout_top, pad=(0, 0))],
[sg.Column(layout_bottom, pad=(0, 0))],
]
layout_right = [[sg.Image(background_color='white', key='im')]]
layout = [
[sg.Column(layout_left), sg.Column(layout_right, pad=(0, 0), size=(w+15, h+15),
background_color='lightblue', key='-COLUMN-')],
]
window = sg.Window("PNG/GIF Viewer", layout, finalize=True)
window['im'].Widget.pack(fill='both', expand=True)
window['im'].Widget.master.pack(fill='both', expand=True)
window['im'].Widget.master.master.pack(fill='both', expand=True)
window['-COLUMN-'].Widget.pack_propagate(0)
image=None
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED:
break
# print(event, values)
if event in ('-FOLDER-', '-FILTER-', 'Search'):
update_listbox(window['-LISTBOX-'], values['-FOLDER-'],
('.png', '.gif'), values['-FILTER-'])
elif event == '-LISTBOX-':
lst = values['-LISTBOX-']
if lst != []:
image=update_image(window['im'], values['-LISTBOX-'][0])
elif event == 'normalize':
if image:
image1=normalise(image, window['im'])
#window['im'].update(data=image1)
#image2=Enhance(image1,window['im'])
if event=='Enhance':
# if image1:
image2 = Enhance(image1, window['im'])
#window['im'].update(data=image2)
if event == 'morph':
image3 = Morph(image2, window['im'])
if event == 'singular':
# if image1:
#image3 = Morph(image2, window['im'])
#window['im'].update(data=image3)
image3=singular_points(image1,window['im'])
window.close()
上面的代码有 Morph 函数,它由腐蚀组成。
有人能告诉我在代码中要修改什么,以便输出图像显示如上所示的侵蚀结果吗?
【问题讨论】:
-
图片的比例是否相同?也许变黑的图像要小很多,因此线条更细,被侵蚀完全去除了?
-
感谢您的回复。你是说图片的形状吗?
-
这只是一种可能性。如果图像更小,那么其中的所有特征也会更小。
标签: python algorithm user-interface image-processing