Skip to content

Instantly share code, notes, and snippets.

@Berkays
Created February 28, 2023 01:23
Show Gist options
  • Save Berkays/f4de77da0f0caa712f05259c7ce73059 to your computer and use it in GitHub Desktop.
Save Berkays/f4de77da0f0caa712f05259c7ce73059 to your computer and use it in GitHub Desktop.
Find corner points of rectangle with 1s border
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 33,
"id": "b5906007-198b-48e9-b179-b817f7b647f7",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import numpy as np\n",
"from skimage import feature"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "b3cdb339-5e46-4d1e-8d4f-5a744dd562ac",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"array([[0., 1., 0., 0., 0., 0.],\n",
" [0., 1., 1., 1., 1., 0.],\n",
" [0., 1., 0., 1., 1., 0.],\n",
" [0., 1., 1., 1., 1., 0.],\n",
" [0., 0., 0., 0., 1., 0.]])"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m = np.array([\n",
" [0,1,0,0,0,0],\n",
" [0,1,1,1,1,0],\n",
" [0,1,0,1,1,0],\n",
" [0,1,1,1,1,0],\n",
" [0,0,0,0,1,0],\n",
"], dtype=float)\n",
"m"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "3982cb0a-a0d6-40ee-bacb-bf1b824f80f1",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"array([[False, False, False, False, False, False],\n",
" [False, True, True, True, True, False],\n",
" [False, True, False, False, True, False],\n",
" [False, True, True, True, True, False],\n",
" [False, False, False, False, False, False]])"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"edges = feature.canny(m)\n",
"edges"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "b4c6e957-d56b-4c80-98cc-21aa4995e847",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"array([[1, 1],\n",
" [1, 4],\n",
" [3, 1],\n",
" [3, 4]])"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"feature.corner_peaks(feature.corner_harris(edges), min_distance=1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fb381aa5-65cc-4532-acfe-d0d0158d0608",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment