587 lines
5.7 MiB
Plaintext
587 lines
5.7 MiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "d7796c8b",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"![Logo 1](img/aitech-logotyp-1.jpg)\n",
|
||
|
"<div class=\"alert alert-block alert-info\">\n",
|
||
|
"<h1> Widzenie komputerowe </h1>\n",
|
||
|
"<h2> 04. <i>Zaawansowane przetwarzanie obrazów i fotografia obliczeniowa</i> [laboratoria]</h2> \n",
|
||
|
"<h3>Andrzej Wójtowicz (2021)</h3>\n",
|
||
|
"</div>\n",
|
||
|
"\n",
|
||
|
"![Logo 2](img/aitech-logotyp-2.jpg)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "1454f22a",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"W poniższych materiałach krótko omówimy zagadnienia związane z fotografią obliczeniową, a większą część czasu pozostawimy na realizację zadania dotyczącego wykrywania linii.\n",
|
||
|
"\n",
|
||
|
"Na początku załadujmy niezbędne biblioteki."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 7,
|
||
|
"id": "245f995f",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import cv2 as cv\n",
|
||
|
"import numpy as np\n",
|
||
|
"import matplotlib.pyplot as plt\n",
|
||
|
"%matplotlib inline"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "58f244a1",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Obrazy HDR\n",
|
||
|
"\n",
|
||
|
"Na poprzednich zajęciach widzieliśmy w jaki sposób można poprawić kontrast np. przy pomocy wyrównania histogramu. W niektórych przypadkach jest to wystarczająca operacja pozwalająca uzyskać zadowalający efekt. Niestety, jest też wiele przypadków gdy na potrzebę uchwycenia głównych elementów na zdjęciu obraz musi mieć mniejszą lub większą ekspozycję, co kończy się niedoświetleniem lub prześwietleniem obiektów znajdujących się np. na drugim planie. Zasadniczo w takiej sytuacji chcielibyśmy wyjść poza standardowy ograniczony zakres wartości 0-255 do jakiegoś szerszego zakresu, który z jednej strony pozwoliłby nam uchwycić więcej informacji znajdujących się na scenie, ale z drugiej strony musimy też pamiętać o ponownej konwersji do standardowego zakresu.\n",
|
||
|
"\n",
|
||
|
"Pokażemy tutaj w jaki sposób można wykorzystać technikę [*High dynamic range (HDR) imaging*](https://en.wikipedia.org/wiki/High-dynamic-range_imaging) w OpenCV do uzyskania obrazu o dużej rozpiętości tonalnej. Poniżej mamy kilka zdjęć tego samego obiektu (źródło: Wikipedia, [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/deed.en)), wykonanych z różnym czasem naświetlania, przez co możemy zauważyć, że część elementów jest niedoświetlona, a część prześwietlona:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 8,
|
||
|
"id": "01f5a664",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAABk4AAAE+CAYAAADLSuwrAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/NK7nSAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOy9ebxtV1En/q3a576XgSQYQhIwDAFC8zEJhCGESQiNEGQSNUS0aQIBARtQQGRQFEEmtVVoY4MIHXDARialkUGQQWWOzEMAGX6AECBAJobknr3q90d9q9Y6551z7rnvveS9hFXwcu/dZ+811qq1z/e7qkrMzNClS5cuXbp06dKlS5cuXbp06dKlS5cuXbp06dIFuq8b0KVLly5dunTp0qVLly5dunTp0qVLly5dunTpsr9IJ066dOnSpUuXLl26dOnSpUuXLl26dOnSpUuXLl0onTjp0qVLly5dunTp0qVLly5dunTp0qVLly5dunShdOKkS5cuXbp06dKlS5cuXbp06dKlS5cuXbp06dKF0omTLl26dOnSpUuXLl26dOnSpUuXLl26dOnSpUsXSidOunTp0qVLly5dunTp0qVLly5dunTp0qVLly5dKJ046dKlS5cuXbp06dKlS5cuXbp06dKlS5cuXbp0oXTipEuXLl26dOnSpUuXLl26dOnSpUuXLl26dOnShdKJky5dunTp0qVLly5dunTp0qVLly5dunTp0qVLF0onTrp06dKlS5cuXbp06dKlS5cuXbp06dKlS5cuXSidOOlytZTLLrsMT37yk3Hd614XBx54IE455RS89a1vXfv5//zP/8QZZ5yBa17zmjj00EPxMz/zM/jCF74wc88PfvADPOxhD8MJJ5yAww47DNe4xjVwi1vcAi94wQuwubk5c++//Mu/4H73ux+ud73r4YADDsDRRx+Ne97znnj3u9+9V/rbpUuXLl2uXNmTfea1r30tfuEXfgE3utGNcNBBB+G//Jf/gl//9V/HhRdeuMu9N7zhDSEiu/x71KMetZd71KVLly5d9hf54Ac/iMc85jE4/vjjcfDBB+P6178+zjjjDHz2s59d6/mXvexlC/cOEcH5559/Bbe+S5cuXbrsC7n00kvx9Kc/Hfe85z1x+OGHQ0Twspe9bOG9D3nIQxbuETe72c3Wru/1r389bnWrW+GAAw7A9a9/fTz96U/HdDrdS73p0mX/kMm+bkCXLleEPOQhD8GrX/1qPO5xj8Nxxx2Hl73sZbjXve6Fd7zjHbjTne608tlLL70Ud73rXXHRRRfhN3/zN7GxsYE/+ZM/wV3uchd85CMfwbWudS0ATpx88pOfxL3udS/c8IY3hKriPe95Dx7/+Mfj/e9/P17xildkmZ/97GehqnjUox6Fo48+Gt/97nfx13/917jzne+Mf/zHf8Q973nPK3Q8unTp0qXL3pU92Wce8YhH4LrXvS4e9KAH4frXvz4+/vGP4+yzz8Yb3/hGfOhDH8KBBx44c/9JJ52EX//1X5+5dtOb3nSv96lLly5duuwf8vu///t497vfjQc84AG4+c1vjvPPPx9nn302bnWrW+F973sfTjjhhLXKe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IIDj30UJx88skz3vldunTp0mXPZefOnSsP7y6ScRxx8cUXb+uZT33qU/jUpz6FRzziEUmaAMD/+B//A2aGV7/61Suf799RulyVpIfq6nK1kw9/+MO46U1vikMPPXTm+m1ve1sAwEc+8hFc73rXW/hsKQUf+9jHdvliEM//0z/9Ey655BIccsghef3yyy/HxRdfjB/84Ac499xz8T//5//EDW5wA9zkJjfZpYyLL74Yl19+OS644AL85V/+JT7xiU/gN3/zN1f25/LLL8dpp52Gyy67DI997GNx9NFH4z//8z/xhje8ARdeeGG6Uj772c/Gb//2b+OMM87Awx/+cHzrW9/Cn/7pn+LOd74zPvzhD6db/lvf+lbc5z73wXWucx382q/9Go4++mh8+tOfxhve8Ab82q/92sq2dOnSpUuXPdtnlknEnD/iiCN2+eztb387DjroIIzjiBvc4AZ4/OMfv5a9/t3f/V0897nPxcMf/nDc9ra3xcUXX4xzzz0XH/rQh3D3u98dAPDJT34Sd7zjHfHjP/7jeMpTnoKDDz4Yf/d3f4f73//+eM1rXpOEzqWXXoqf/MmfxKc//WmcddZZuNWtboULLrgAr3/96/HVr351Ybu7dOnSpcveEzPDN77xDRx//PFrP3PXu94Vl156KXbs2IHTTjsNf/RHf4Tjjjtu5TPf/OY3cY973APXvva18ZSnPAXXvOY18aUvfQmvfe1rZ+575CMfmZ4tv/qrv4ovfvGLOPvss/HhD38Y7373u7GxsQHAvV/OOussHH/88XjqU5+Ka17zmvjwhz+MN7/5zfilX/ql7Q9Ely5dunTZK/L9738fhx56KL7//e/jx37sx/CLv/iL+P3f/31c4xrXWPnchz/8YQDYxaPxute9Lo455pj8fJn07yhdrlJiXbpczeT444+3//pf/+su1z/5yU8aAHvRi1609NlvfetbBsCe+cxn7vLZn/3ZnxkAO++882au/+3f/q0ByH+3uc1t7GMf+9jC8k877bS8b8eOHfbIRz7SfvCDH6zsz4c//GEDYK961auW3vOlL33JhmGwZz/72TPXP/7xj9tkMsnr0+nUjj32WLvBDW5g3/3ud2fuLaWsbEeXLl26dHHZk31mmTzsYQ+zYRjss5/97Mz1+973vvb7v//79vd///f20pe+1H7yJ3/SANiTnvSkLcu8xS1uYfe+971X3nO3u93NTjzxRPvhD3+Y10opdoc73MGOO+64vPY7v/M7BsBe+9rX7lJG3z+6dOnS5YqXv/qrvzIA9tKXvnTLe1/5ylfaQx7yEHv5y19ur3vd6+xpT3uaHXTQQXbEEUfYl7/85ZXPvu51rzMA9sEPfnD
|
||
|
"text/plain": [
|
||
|
"<Figure size 2000x500 with 4 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"exposure_times = np.array([ 1/30.0, 0.25, 2.5, 15.0 ], dtype=np.float32)\n",
|
||
|
" \n",
|
||
|
"f_names = [\"st-louis-arch-0.033.jpg\", \n",
|
||
|
" \"st-louis-arch-0.25.jpg\", \n",
|
||
|
" \"st-louis-arch-2.5.jpg\", \n",
|
||
|
" \"st-louis-arch-15.jpg\"]\n",
|
||
|
"\n",
|
||
|
"plt.figure(figsize=(20,5))\n",
|
||
|
"images = []\n",
|
||
|
"for i, f_name in enumerate(f_names):\n",
|
||
|
" image = cv.imread(f\"img/{f_name}\", cv.IMREAD_COLOR)\n",
|
||
|
" images.append(image)\n",
|
||
|
" \n",
|
||
|
" plt.subplot(141 + i)\n",
|
||
|
" plt.imshow(image[:,:,::-1])\n",
|
||
|
" plt.title(f\"{str(round(exposure_times[i], 3))} sec.\")"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "9cb65411",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Szczegółowy opis dalszych kroków można znaleźć np. w rozdziale *10.1 Photometric calibration* i *10.2 High dynamic range imaging* książki R. Szeliski *Computer Vision* (2021) - tutaj ograniczymy się do technicznego rozwiązania kolejnych problemów.\n",
|
||
|
"\n",
|
||
|
"Pierwszym problemem, który musimy rozwiązać, jest wyrównanie/dopasowanie obrazów. Nawet jeśli zdjęcie jest robione ze statywu (lub gorzej - z ręki), to po nałożeniu zdjęć na siebie będą widoczne artefakty wynikające z wibracji i przesunięć. W OpenCV możemy to rozwiązać poprzez funkcję [`cv.createAlignMTB()`](https://docs.opencv.org/4.5.3/d7/db6/classcv_1_1AlignMTB.html), która tworzy tzw. bitmapy z progiem mediany (ang. *median threshold bitmaps*), w których zawartość obrazu jest obliczana przez przypisanie wartości 1 pikselom jaśniejszym niż mediana luminancji i 0 w przeciwnym wypadku."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 9,
|
||
|
"id": "7dda882f",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"align_mtb = cv.createAlignMTB()\n",
|
||
|
"align_mtb.process(images, images)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "8873862f",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"W dalszych krokach musimy:\n",
|
||
|
"\n",
|
||
|
"* oszacować radiometryczną funkcję odpowiedzi na podstawie wyrównanych obrazów,\n",
|
||
|
"* oszacować mapę radiacyjną, wybierając lub mieszając piksele z różnych ekspozycji,\n",
|
||
|
"* wykonać mapowanie tonalne wynikowego obrazu HDR z powrotem do postaci umożliwiającej jego normalne wyświetlanie."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 10,
|
||
|
"id": "bd00b46f",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"calibrate_debevec = cv.createCalibrateDebevec()\n",
|
||
|
"response_debevec = calibrate_debevec.process(images, exposure_times)\n",
|
||
|
"merge_debevec = cv.createMergeDebevec()\n",
|
||
|
"hdr_debevec = merge_debevec.process(images, exposure_times, response_debevec)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "d6c1f8f3",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Teoretycznie moglibyśmy zapisać teraz wynikowy plik `.hdr` np. przy pomocy `cv.imwrite(\"hdr_debevec.hdr\", hdr_debevec)` i edytować dalej go w programie graficznym. W tym miejscu jednak wykonamy dalszą obróbkę przy pomocy OpenCV, tj. wykonamy mapowanie tonalne. Poniżej mamy zaprezentowane wyniki uzyskane metodą Reinharda i Mantiuka:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 11,
|
||
|
"id": "4a16094f",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAi0AAAGiCAYAAAAr5/biAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/NK7nSAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOz9e6xt2VEfjP5qrrX3Pn26+5x+9+m2224/ANN+YF1CjJVAuIFgESefknCjXEh4JBEIZJCCFeQ4QuElYRTpKkg3r38Q0VVAX5JPJJHIDR+PEPIRzOUVYmzixm5wt00/7e4+p1/n7L3XrPvHHFX1qxpj7nNM7GBO79G9z5przvGoqlH1q5rjtURVFafpNJ2m03SaTtNpOk2f42n6oybgNJ2m03SaTtNpOk2n6VrSadBymk7TaTpNp+k0naY/Fuk0aDlNp+k0nabTdJpO0x+LdBq0nKbTdJpO02k6Tafpj0U6DVpO02k6TafpNJ2m0/THIp0GLafpNJ2m03SaTtNp+mORToOW03SaTtNpOk2n6TT9sUinQctpOk2n6TSdptN0mv5YpNOg5TSdptN0mk7TaTpNfyzSadBymk7TaTpNp+k0naY/FulzOmj5J//kn+D+++/HmTNn8La3vQ2/+qu/+kdN0mk6TafpNJ2m03Sa/ojS52zQ8q/+1b/Cu9/9bnzv934vfvM3fxNf9EVfhHe84x148skn/6hJO02n6TSdpt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/5gjQreQjeotSQa028alWKRmOmbHweywIuz7+AkrR2KnFw2rCXqsja7Di50+3Uxmc5bEf4OJvmDzqI2SsF4ImI48sX
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"tonemap_rReinhard = cv.createTonemapReinhard(1.5, 0,0,0)\n",
|
||
|
"ldr_reinhard = tonemap_rReinhard.process(hdr_debevec)\n",
|
||
|
"plt.imshow(ldr_reinhard[:,:,::-1]);"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 12,
|
||
|
"id": "92cdbefa",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAi0AAAGiCAYAAAAr5/biAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/NK7nSAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOz9W6xu2XEWDD8137XWPu/d525bcZzDRwgmDpaCcSxCyAchFhgkIEIoQBIOCkrUiUQsImMUkZMUR7khF5xuULggkQAJhBRE/hyACIgj+IMgpw9DTJJ27O522929d/c+rvXO+i/GqKqnaoy59nZ++4uzvYa9e813znGoqlH1VI3TnKKqirN0ls7SWTpLZ+ksnaXP8LT8dhNwls7SWTpLZ+ksnaWz9CDpLGg5S2fpLJ2ls3SWztLviHQWtJyls3SWztJZOktn6XdEOgtaztJZOktn6SydpbP0OyKdBS1n6SydpbN0ls7SWfodkc6ClrN0ls7SWTpLZ+ks/Y5IZ0HLWTpLZ+ksnaWzdJZ+R6SzoOUsnaWzdJbO0lk6S78j0lnQcpbO0lk6S2fpLJ2l3xHpLGg5S2fpLJ2ls3SWztLviPQZHb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9KAsAGGBbAd3FCsPYSvAQeUEB7tjLCJMytos0qzcOaYvce6YTl0040zklBgyApzoAbhczeDgeHc4onPGm0KF6GZuxz6aBuI7gaaPtMfU/L/7/pxo0buHbtGt74pi/GstsFuDPmoBillC7hUT3fRwkuEMbPgO75tBRSgtdsMal8azgMzQAvQZ4QX72Cta9/LKliIINKPGI
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"tonemap_mantiuk = cv.createTonemapMantiuk(2.2, 0.85, 1.2)\n",
|
||
|
"ldr_mantiuk = tonemap_mantiuk.process(hdr_debevec)\n",
|
||
|
"ldr_mantiuk = np.clip(3 * ldr_mantiuk, 0, 1)\n",
|
||
|
"plt.imshow(ldr_mantiuk[:,:,::-1]);"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "c4d83478",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Gładkie klonowanie\n",
|
||
|
"\n",
|
||
|
"Na wcześniejszych zajęciach widzieliśmy, że możemy umieszczać elementy jednego obrazu w drugim obrazie np. poprzez wykorzystanie maski i kanału dotyczącego przezroczystości. Innym ciekawym podejściem jest praca na gradientach obrazu (zamiast na jego intensywności), co może dać równie interesujące, a czasem i bardziej realistyczne wyniki. W tzw. gładkim klonowaniu (ang. *seamless cloning*) intensywność obiektu docelowego będzie różna od intensywności obiektu źródłowego, natomiast gradienty będą podobne. Szczegóły omawianej metody znajdują się w artykule P. Perez et al. (2003) [*Poisson Image Editing*](https://www.irisa.fr/vista/Papers/2003_siggraph_perez.pdf).\n",
|
||
|
"\n",
|
||
|
"Poniżej mamy obraz basenu i kąpiących się w nim ludzi oraz niedźwiedzia, którego chcemy umieścić w basenie:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 13,
|
||
|
"id": "e0d74bf3",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAABkgAAAHDCAYAAABvWJarAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/NK7nSAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOz9ebRtV1Unjn/mXHuf+95LCEGaYEBBpYog+LMBwkA6gwJGUFGRrlCMitgE1Mj4IioU2GGHBUUjaOnAUYKDQhl2CCrYoYJSUGVTdqioFKUgXSDJe/ecveb8/THnXGvtc2+AIJDwmJ+Ml3vvOfvsvbq9z96fz/zMSaqqSCQSiUQikUgkEolEIpFIJBKJRCKR+DgCX98NSCQSiUQikUgkEolEIpFIJBKJRCKR+GgjBZJEIpFIJBKJRCKRSCQSiUQikUgkEh93SIEkkUgkEolEIpFIJBKJRCKRSCQSicTHHVIgSSQSiUQikUgkEolEIpFIJBKJRCLxcYcUSBKJRCKRSCQSiUQikUgkEolEIpFIfNwhBZJEIpFIJBKJRCKRSCQSiUQikUgkEh93SIEkkUgkEolEIpFIJBKJRCKRSCQSicTHHVIgSSQSiUQikUgkEolEIpFIJBKJRCLxcYcUSBKJRCKRSCQSiUQikUgkEolEIpFIfNwhBZJE4mMQv/u7vwsiwu/+7u9e301p+Md//EcQEV74whde3035qOKpT30qiOj6bkYikUgkEolEIpFIJBKJRCKRuI5IgSSR+Ajhz//8z/GQhzwEt7nNbXDixAnc6la3wv3udz88+9nPvr6blkgkEolEIpFIJBKJRCKRSCQSH/eYru8GJBJnI/7oj/4Il1xyCT75kz8Zj3nMY3DLW94Sb3nLW/C6170Oz3rWs/C4xz3u37X/e9/73jh9+jQ2m82HqcX/ftzmNrfB6dOnMc/z9d2URCKRSCQSiUQikUgkEolEIpH4gEiBJJH4COAHfuAHcOMb3xivf/3rcf7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CKRSCQSiUQikUgkEolE4mMXKZAkEh9hbDYb3PWud8UP/uAP4id+4iew2+3w0pe+tL1/z3veE69//etx5syZJpCcf/75uNOd7oTXvOY1TTz5YASSUsp1en2szfH+tr0un/9gP5tIJBKJRCKRSCQSiUQikUgkEtcnUiBJJD6KuMtd7gIA+Jd/+Zf22r3udS9st1v8/M//PN761rc2IeTe9753E0j+43/8j7jggguulzZ/NHCb29wG//Iv/4Jrrrlm9frf/d3fXaf9vOlNb1r9fdVVV+Ff/uVfcNvb3rYdBwD+5m/+ZrXddrvFm9/85vb+tW0Xr8X7iUQikUgkEolEIpFIJBKJROJjFymQJBIfAfzO7/zOse6KqIUxpm66293uhnme8cM//MP4hE/4BNzxjncEYMLJ6173Ovze7/3eB+Ue+VjGAx7wAOx2O/zUT/1Ue01E8NznPvc67ecnf/Insdvt2t8/8RM/gWVZcOmllwIAvuALvgCbzQb/9b/+19X8/PRP/zSuvPJKPPCBDwRgQtYtbnELPP/5z8fh4WHb7hWveAX+6q/+qm2XSCQSiUQikUgkEolEIpFIJD52MV3fDUgkzkY87nGPwzXXXIMv+7Ivw0UXXYTtdos/+qM/wkte8hLc9ra3xWWXXda2PXXqFO585zvjda97Hb74i7+41RC5973vjauvvhpXX331WS+QPPjBD8bFF1+M7/iO78Df/d3f4aKLLsKv/Mqv4F3vehcAHKmrcm3Ybrf4/M//fDz0oQ/F3/zN3+B5z3se7nnPe+JLvuRLAAA3v/nN8aQnPQlPe9rT8IVf+IX4ki/5krbdXe96VzzqUY8
|
||
|
"text/plain": [
|
||
|
"<Figure size 2000x500 with 3 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"swimmingpool = cv.imread(\"img/swimmingpool.jpg\", cv.IMREAD_COLOR)\n",
|
||
|
"bear = cv.imread(\"img/bear.jpg\", cv.IMREAD_COLOR)\n",
|
||
|
"bear_mask = cv.imread(\"img/bear-mask.jpg\", cv.IMREAD_GRAYSCALE)\n",
|
||
|
"\n",
|
||
|
"plt.figure(figsize=(20,5))\n",
|
||
|
"plt.subplot(131)\n",
|
||
|
"plt.imshow(swimmingpool[:,:,::-1])\n",
|
||
|
"plt.title(\"Swimming pool\")\n",
|
||
|
"plt.subplot(132)\n",
|
||
|
"plt.imshow(bear[:,:,::-1])\n",
|
||
|
"plt.title(\"Bear\")\n",
|
||
|
"plt.subplot(133)\n",
|
||
|
"plt.imshow(bear_mask[:,:], cmap='gray')\n",
|
||
|
"plt.title(\"Bear mask\");"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "7654ece6",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Przy pomocy metody [`cv.seamlessClone()`](https://docs.opencv.org/4.5.3/df/da0/group__photo__clone.html#ga2bf426e4c93a6b1f21705513dfeca49d) wykonujemy gładkie klonowanie:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 14,
|
||
|
"id": "f6d3092b",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA0cAAALiCAYAAAASHK1qAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/NK7nSAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOy9ebR9R1Un/tlV59z3Mpkgs4KJBgUCS4KBYCuTqAwGBEXAbm1IHOiByI8GuxVdKtitAVx24wQ2rNYIatttI7qWE4iC2g4tNrqWiii2gCORecr3++45Vfv3xx5qV937TUIEwa+3MH7fu+/cc+rs2rX3Z49FzMw4jMM4jMM4jMM4jMM4jMM4jMP4Jz7Sx3oCh3EYh3EYh3EYh3EYh3EYh3EYHw/jYBwdxmEcxmEcxmEcxmEcxmEcxmHgYBw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ifi537u5/C2t73NaXZLI4Y/9mM/hrvf/e44Pj7GFVdcgV/7tV/bueav//qv8VVf9VW44x3viKOjI9zrXvfCD/3QD92i+1tt0y15DgC8973vxdVXX42LLroIF154Ia655hrceOON3TXruuI//sf/iEsvvRRHR0e45JJL8E3f9E04OTnxay655BL80R/9EX71V3/VaRJp++d//ud4whOegE/8xE/Eueeei8/+7M/Gz/3cz+3M5/u+7/twr3vdC+eeey5uc5vb4H73u9/OGn8k521zf/SjH41Xv/rVuPzyy3F8fIzLLrsMP/VTP9VdZ2m2v/Zrv4Z/9a/+FW5729viEz7hE/DkJz8Z73nPe3bm+Au/8At40IMehPPOOw8XXHABrrrqKvzRH/3RznU//dM/jXvf+944Pj7Gve99b7zyla/cueYwDuMwzv5xMI4O4zAO46wYD37wg/H0pz8dAPBN3/RNePnLX46Xv/zluOc97+nX/Nmf/Rm+7Mu+DF/4hV+I7/7u78ZtbnMbXH311XuB0jje85734JGPfCTuc5/74Lu/+7txj3vcA9/wDd+AX/iFXzjjd06dOoXHPOYx+M3f/E285jWvwed8zufsve6e97wnvv3bvx0A8NSnPtXn/uAHP/jv9XwAePzjH49XvvKVuOaaa/CiF70IT3/60/GBD3wAf/EXf3Gz71xKwaMe9Sjc9a53xQte8AJccskluPbaa3H99dfjkY98JO53v/vh+c9/Pi644AI8+clPxlve8pabvN+LX/xiXHvttbjLXe6CF7zgBXjQgx6Exz3ucfirv/qrvdc/73nPwytf+Up8/dd/PZ797Gfjt3/7t/EVX/EV/vdv/uZvxuWXX47b3e52TrNbUn/0q7/6q3jGM56Br/zKr8S3f/u3413vehce+chH4g//8A/9mhtuuAGf/dmfjde85jW49tpr8T3f8z24293uhq/+6q++xTVOt+Q5Np74xCfiAx/4AK677jo88YlPxPXXX4/nPve53TVf8zVfg2/91m/FZ33WZ+G//Jf/goc85CG47rrr8OVf/uV+zQtf+ELc5S53wT3ucQ+nyTd/8zf7O33O53wOXvWqV+Hf/tt/i+/4ju/A6dOn8cVf/MWdIfDSl74UT3/603HZZZfhhS98IZ773Ofi8ssvx//5P//nozZvG29+85vxpCc9CY961KNw3XXXYZomPOEJT8Av/dIv7Vx77bXX4o//+I/xnOc8B09+8pPxYz/2Y3jc4x4HZvZrXv7yl+Oqq67C+eefj+c///n4lm/5FrzxjW/EAx/4wM5B8OpXvxqPf/zjQUS47rrr8LjHPQ7XXHPNzdY5HsZhHMZZOPgwDuMwDuPjfPzwD/8wA+DXv/71N3ndT/7kTzIAfu1rX7vzt4svvpgB8K/92q/5Z3/3d3/HR0dH/KxnPcs/e+1rX7tzj4c85CEMgF/2spf5ZycnJ3ynO92JH//4x+989yd/8if5Ax/4AD/kIQ/h293udvx7v/d7N/uOr3/96xkA//AP//DO327p89/ylrd093jPe97DAPi7vuu7bvb543jKU57CAPg7v/M7/bP3vOc9fM455zAR8U/8xE/4529605sYAH/bt32bfzbS8eTkhG9729vy/e9/f16Wxa+7/vrrGQA/5CEP2fnuPe95Tz45OfHPv+d7vocB8B/8wR/4Z1dddRVffPHFt/i9ADAA/t3f/V3/7G1vexsfHx/zl3zJl/hnX/3VX813vvOd+Z3vfGf3/S//8i/nCy+8kG+88caPyHO+7du+jQHwV33VV3Xf/5Iv+RK+7W1v67///u//PgPgr/mar+mu+/qv/3oGwL/yK7/in93rXvfq6GnjGc94BgPgX//1X/fPPvCBD/Cnfuqn8iWXXMKlFGZmfuxjH8v3ute9bvL9Phrztj36ile8wj973/vex3e+8535vve9r39m8uCKK67g7Xbrn7/gBS9gAPwzP/Mz/m4XXXQRf+3Xfm337Le//e184YUXdp9ffvnlfOc735nf+973+mevfvWrGcCHxV+HcRiH8Y9/HCJHh3EYh/FPZlx22WV40IMe5L/f/va3x93vfnf8+Z//+c1+9/zzz8dXfuVX+u+bzQZXXnnl3u++733vw8Mf/nC86U1vwute97pb3WDh1j7fxjnnnIPNZoPXve51e9ONbsn4mq/5Gv/5oosuwt3vfnecd955eOITn+if3/3ud8dFF110k3P53d/9XbzrXe/C137t12KaWrnrV3zFV+A2t7nN3u9cc801XUMHW7tbsl43Nf7ZP/tnuOKKK/z3T/mUT8FjH/tYvOpVr0IpBcyMV7ziFXjMYx4DZsY73/lO/+8Rj3gE3ve+9+ENb3jD3/s5cfzrf/2vu98f9KAH4V3vehfe//73AwB+/ud/HgDwzGc+s7vuWc96FgDsTY0bx8///M/jyiuvxAMf+ED/7Pzzz8dTn/pUvPWtb8Ub3/hGALLOf/VXf4XXv/71N3vPj/S8P+mTPglf8iVf4r9butzv/d7v4e1vf3t37VOf+tSu+ci/+Tf/BtM0+TN/6Zd
|
||
|
"text/plain": [
|
||
|
"<Figure size 1000x1000 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"center = (250,700)\n",
|
||
|
"\n",
|
||
|
"swimmingpool_with_bear = cv.seamlessClone(bear, swimmingpool, bear_mask, center, cv.NORMAL_CLONE)\n",
|
||
|
"\n",
|
||
|
"plt.figure(figsize=(10,10))\n",
|
||
|
"plt.imshow(swimmingpool_with_bear[:,:,::-1])\n",
|
||
|
"plt.title(\"I think this might be photoshopped\");"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "2337a4c3",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Spróbujmy teraz umieścić tekst na teksturze:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 15,
|
||
|
"id": "f61aaaaf",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAABCYAAAGXCAYAAABvBVFIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/NK7nSAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOz9aa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xdcbXbMUyO4CIperxzhJjQ2lKUhmHsePjgIcF7VusNymqIYJTBGosQgBZM4wQIjLaAJKWAsgohJGM/sD/sePz4IQLQ2rJqGo6OT1it1kzO4dxEIpJiYr/bcbTdIIVgnEb6ruPpxROOjk6QQmKLEltYEuCmwJMnD9FCc+vknBAjpjSYwjCMI2134Hp/YH99iR89t8/v8hmf+Rkc+pYIBB9xfsJ5R3COq6tLri8vWdUNq1XDOA1cX12zbw8E5xi6gdtnd/kTf+JL+LX/+l+QAqw1bJs1GsGb33APlwI//0v/mTt37vHcrTuEGHHBUW82XO6vuXh6ycl2w2e86QU+7Y3naKFoyoJhHBkiXO17CqsRQrAfRrwsePWq4zd+8wM8ePKIzfaYumyQQiKEICZPP/SM08hht+Pi6VPWzZrzW2dYY7l1ds7jp09ou55Hjx5gbcGn/qE/RF2tON4ecXZ+TFkVPL3ecXF5yW63J0TPNI5Mw4T3juAdIUSEFEz9AERiisSY8C7QNDVFVVLYGqkU17sr+r7lyeOHxJC4fec5jk9OQcDhcCB4T1XXSARX15e8/MEPs96uWK837A87Lh4/5mh7xPn5LWLw7PZXXF/u2B6dIrVhtVmhjUVKwcNHD2j3e8ah497zb2B7fJqvm76
|
||
|
"text/plain": [
|
||
|
"<Figure size 2000x500 with 2 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"texture = cv.imread(\"img/texture.jpg\", cv.IMREAD_COLOR)\n",
|
||
|
"bologna = cv.imread(\"img/bologna-on-wall.jpg\", cv.IMREAD_COLOR)\n",
|
||
|
"\n",
|
||
|
"plt.figure(figsize=(20,5))\n",
|
||
|
"plt.subplot(131)\n",
|
||
|
"plt.imshow(texture[:,:,::-1])\n",
|
||
|
"plt.title(\"Texture\")\n",
|
||
|
"plt.subplot(132)\n",
|
||
|
"plt.imshow(bologna[:,:,::-1])\n",
|
||
|
"plt.title(\"Bologna to clone\");"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "99a99732",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"W tym wypadku stworzenie maski może być problematyczne, zatem możemy pójść na skróty i przyjąć, że cały obraz stanowi maskę. Przy takim podejściu zobaczymy jednak, że opcja [`cv.NORMAL_CLONE`](https://docs.opencv.org/4.5.3/df/da0/group__photo__clone.html#gabfc4ba1d1fb873f2b56d34032f86c1d4) spowoduje mocne rozmazanie wokół wklejanej części, stąd też lepszym rozwiązaniem będzie opcja `cv.MIXED_CLONE`, co wynika z kombinacji gradientów z jednego i drugiego obrazu:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 16,
|
||
|
"id": "a64d730e",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAABkYAAAJSCAYAAACWQ3ljAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/NK7nSAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOz9e7R1WVnfiX/mbV325Vzea1FQVlElrQKCCkq8FgiKoulhDDGt0QBGQ7dtHLZNfl0ggqgJZpgLRB0Gkg4wvGSkNbET0kbsiEmMjY2akNgaTYGCWFC393LO2Xuvteb198ezzinKAqwi4WbNzxjvqDr77L3P2nutNefzzPl9vo8qpRQqlUqlUqlUKpVKpVKpVCqVSqVSqVQeBeiP9wFUKpVKpVKpVCqVSqVSqVQqlUqlUql8rKgbI5VKpVKpVCqVSqVSqVQqlUqlUqlUHjXUjZFKpVKpVCqVSqVSqVQqlUqlUqlUKo8a6sZIpVKpVCqVSqVSqVQqlUqlUqlUKpVHDXVjpFKpVCqVSqVSqVQqlUqlUqlUKpXKo4a6MVKpVCqVSqVSqVQqlUqlUqlUKpVK5VFD3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uf+bP/JmSUnrQ73LOH/K9XvOa1xSg/MRP/MTZY9778vmf//lltVqV4+PjUkopv//7v1+Acv78+XL16tWz5/6zf/bPClDe/OY3nz327Gc/u3zmZ35mGcfxQcfwBV/wBeUJT3jCh/0clUqlUqlUKpVK5WPHB+ZSP/IjP1LW6/VZnvLn/tyfK8961rNKKZIXfdVXfdWDXguUV77ylQ967KUvfWnRWpd/+2//bfnpn/7pApTXvOY1Z7//5V/+5QKUn/zJn3zQ637+53/+QY/fe++9pWma8lVf9VUPymde9rKXFaC84AUv+LCf661vfWsBHpQXnvKB73fzzTc/6L2+8zu/swDll3/5l88eOzk5KY9//OPLLbfccpZrneaDn/EZn1GmaTp77mtf+9oClN/8zd88+1tPeMITynOf+9wH/d3dblce//jHly/7si/7sJ+jUqlU/iRQK0YqlUrlY8Ctt97KN33TN/H617+e97///R/0OT/3cz8HwHd913c96PH/9X/9XwEeUib9+Mc/nuc+97kf9L3+4l/8izjnzn5+xjOeQSmFb/7mb37Q857xjGfw3ve+90GevX3fn/3/0dER999/P7fffju/93u/x9HR0R/3UR/E//l//p/knHnFK16B1g+ecpRSH/J1P/dzP8cNN9zA13/915895pzjO77jO9hsNvybf/NvHvT8P//n/zyHh4dnP3/xF38xIOXmIKXyb33rW/m6r/s6Tk5OuP/++7n//vu5cuUKz33uc7nzzju56667HtFnq1QqlUqlUqlUKh99vu7rvo5hGPgX/+JfcHJywr/4F//iQ9pofSi+93u/lyc96Um84AUv4Nu+7du4/fbb+Y7v+I6z3//0T/80+/v7fNmXfdlZrnD//ffztKc9jdVqxS/90i8B8K/+1b/Ce89f+St/5UH5zHd+53c+rOP4J//kn6CU4pWvfOVDfvfH5Uef93mfxxd90RedPbZarfjLf/kv8+53v5vf/u3fftDzX/SiF9E0zdnPfzQ/esc73sGdd97JN3zDN3DlypWzz7vdbnn2s5/Nv/23/5ac88P6TJVKpfLJSu1GValUKh8jXv7yl/PjP/7j/OAP/uAHtYN6z3veg9aaT/3UT33Q4zfccAMHBwe85z3vedDjj3/84z/k3/qUT/mUB/28v78PwE033fSQx3POHB0dcf78eQB+5Vd+hVe+8pW87W1vY7fbPej5R0dHZ+/1cHjXu96F1ponPvGJD/s1IN/FE57whIdspnzGZ3zG2e8/kD/6eU83SU79gN/5znd
|
||
|
"text/plain": [
|
||
|
"<Figure size 2000x1000 with 2 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"mask = 255 * np.ones(bologna.shape, bologna.dtype)\n",
|
||
|
"\n",
|
||
|
"width, height, channels = texture.shape\n",
|
||
|
"center = (height//2, width//2)\n",
|
||
|
"\n",
|
||
|
"normal_clone = cv.seamlessClone(bologna, texture, mask, center, cv.NORMAL_CLONE)\n",
|
||
|
"mixed_clone = cv.seamlessClone(bologna, texture, mask, center, cv.MIXED_CLONE)\n",
|
||
|
"\n",
|
||
|
"plt.figure(figsize=[20,10])\n",
|
||
|
"plt.subplot(121)\n",
|
||
|
"plt.title(\"Normal clone\")\n",
|
||
|
"plt.imshow(normal_clone[:,:,::-1])\n",
|
||
|
"plt.subplot(122)\n",
|
||
|
"plt.title(\"Mixed clone\")\n",
|
||
|
"plt.imshow(mixed_clone[:,:,::-1])\n",
|
||
|
"plt.show()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "b3df663d",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Usuwanie niechcianych obiektów\n",
|
||
|
"\n",
|
||
|
"Spróbujemy teraz usunąć ze zdjęcia defekty, które często są domeną starych fotografii. Poniżej mamy zdjęcie prezydenta Lincolna z rysą na poziomie włosów; dodatkowo ręcznie ustaliliśmy maskę wskazującą miejsce występowania tej rysy:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 17,
|
||
|
"id": "35d05105",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
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qPRKa9dq9XwIz/yIzh48CBuuOEGPOEJT/gP98fDw+PMgyfCPDzOMrDel2JiYgKVSsX+v++++7Bjx44xEsXF0aNHEY1GsX///rHX5+bmUC6XcfTo0dO25ZxzzjmpHQDG2vJQceedd+LHfuzHUCqVUCwWMTMzY4QT63/t27cPb3nLW/AXf/EXmJ6exvOf/3z86Z/+qb3/H8H5558/9n8kEsH+/ftx5MiRsdd37dplZCLh2v/o0aM4//zzEY2OL9EXX3yxvX8q8P0LL7zwpPcuvvhirKysoNVqnbpDHh4eHh4eHh7fB8zMzODqq6/GRz7yEfzDP/wDhsMhXvGKV4Qe++lPfxpPe9rTkE6nMTk5aaUh9N7tVa96FZ7xjGfgDW94A7Zt24ZXv/rV+NjHPhZKiv3Kr/wKvvnNb+JLX/oSfuiHfuj71kcPD49HNzwR5uFxluF7vYukS+o8HGzVliAIHtZ5qtUqrrzyStx222145zvfiX/6p3/CF7/4Rbz73e8GgLEboT/8wz/E7bffjre+9a3odDp405vehB/6oR/CsWPHvut+PBx8r/rs4eHh4eHh4XGm4jWveQ0++9nP4s/+7M9wzTXXmKpL8dWvfhUvfvGLkU6n8f73vx+f+cxn8MUvfhGvec1rxu6bMpkMbrzxRnzpS1/Ca1/7Wtx+++141atehec973knbZr0kpe8BEEQ4F3vetdp1WMeHh6PXXgizMPD4yScd955OHHiBNbW1rY8Zs+ePRiNRrj33nvHXl9cXES1WsWePXu+38003HDDDVhdXcW
|
||
|
"text/plain": [
|
||
|
"<Figure size 1500x1000 with 2 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"lincoln = cv.imread(\"img/lincoln.jpg\", cv.IMREAD_COLOR)\n",
|
||
|
"lincoln_mask = cv.imread(\"img/lincoln-mask.jpg\", cv.IMREAD_GRAYSCALE)\n",
|
||
|
"\n",
|
||
|
"plt.figure(figsize=(15,10))\n",
|
||
|
"plt.subplot(121)\n",
|
||
|
"plt.imshow(lincoln[:,:,::-1])\n",
|
||
|
"plt.title(\"Lincoln last photo\")\n",
|
||
|
"plt.subplot(122)\n",
|
||
|
"plt.imshow(lincoln_mask[:,:], cmap='gray')\n",
|
||
|
"plt.title(\"Mask\");"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "ba912b4f",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Używając metody [`cv.inpaint()`](https://docs.opencv.org/4.5.3/d7/d8b/group__photo__inpaint.html#gaedd30dfa0214fec4c88138b51d678085) możemy przywrócić wybrany region w obrazie przy pomocy sąsiedztwa zadanego regionu. Metoda `cv.INPAINT_NS` implementuje podejście opisane w M. Bertalmio et al. (2001) [*Navier-Stokes, Fluid Dynamics, and Image and Video Inpainting*](https://www.math.ucla.edu/~bertozzi/papers/cvpr01.pdf), która ogólnie mówiąc ma za zadanie zachować gradienty (np. krawędzie) i rozprowadzać informacje o kolorach na płaskich przestrzeniach. Z kolei `cv.INPAINT_TELEA` implementuje metodę opisaną w A. Telea (2004) [*An image inpainting technique based on the fast marching method*](https://core.ac.uk/download/pdf/148284148.pdf). W obu przypadkach możemy zauważyć oczekiwane wypełnienie na poziomie włosów, aczkolwiek po prawej stronie jest widoczne pewne rozmazanie - być może należałoby poprawić/zawęzić wejściową maskę."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 18,
|
||
|
"id": "52ff1513",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAABMIAAAHmCAYAAACRciInAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/NK7nSAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOz9ebhlRXU3jn/2mefhTn37Nk3TzJNCQiIhAg2KD6JvEiJGMSYCGs2gMX6JMWIMgmMUB9TEmOR93ohmQo2a503iPMQ3zhqNUURBmqbp7jufe+b57N8f5/ep89l1z226oenuC7We5z73nH32rl21aq31qVprVZXn+74PR44cOXLkyJEjR44cOXLkyJEjR44e4xQ61hVw5MiRI0eOHDly5MiRI0eOHDly5OhokHOEOXLkyJEjR44cOXLkyJEjR44cOXpckHOEOXLkyJEjR44cOXLkyJEjR44cOXpckHOEOXLkyJEjR44cOXLkyJEjR44cOXpckHOEOXLkyJEjR44cOXLkyJEjR44cOXpckHOEOXLkyJEjR44cOXLkyJEjR44cOXpckHOEOXLkyJEjR44cOXLkyJEjR44cOXpckHOEOXLkyJEjR44cOXLkyJEjR44cOXpckHOEOXLkyJEjR44cOXLkyJEjR44cOXpckHOEOToqdP/998PzPHzgAx841lXBZZddhssuu+yIlfeBD3wAnufh/vvvP2JlHg267LLLcO655x7rajhy5MjRI6Lj1QZff/31OOmkk451NR423XLLLfA871hX44jTSSedhP/1v/7Xsa6GI0eOHD0icti3MR2vvHF0fJFzhDl6xERj8+1vf/tYV+UxSW9+85vxiU984lhX4yGp0WjglltuwZe+9KVjXRVHjhw9ivRYsvl33XUXbrnlluNysOx5HjzPwzve8Y51vz2W+gAAOp0O3v3ud+NnfuZnkMvlUCgUcM455+AlL3kJ7r77bnPfV7/6Vdxyyy1YW1s7dpV15MjR45IeS3b3eMS+66+/3uDewf6uv/76Y11VR48RihzrCjh6fNCOHTvQbDYRjUaPdVU2Hb35zW/Gs5/9bFx99dXHuioHpUajgVtvvRUAjmjGnSNHjhwdjH7zN38T1157LeLx+GE/e9ddd+HWW2/FZZdddswj2BvRbbfdht/93d9FKpU6qu997Wtfi1e/+tVH5V3XXHMNPvnJT+J5z3seXvziF6Pb7eLuu+/Gv/7rv+IXf/EXceaZZwIYOsJuvfVWXH/99SgUCkelbo4cOXJ0PNJjDft++7d/G1dccYX5vnv3btx88814yUtegksuucRcP+WUU45F9Rw9Bsk5whwdFfI8D4lE4lhXw5EjR44cPcYoHA4jHA4f62o8KnT++efje9/7Ht7//vfjxhtvPKrvjkQiiESO3DCx0WiMdeZ961vfwr/+67/iTW96E17zmtcEfvvzP/9zl/3lyJEjR2PosYZ9F110ES666CLz/dvf/jZuvvlmXHTRRfiN3/iNY1gzR49VcksjHR0VGrdH2PXXX49MJoN9+/bh6quvRiaTwfT0NF75ylei3+8Hnh8MBnj3u9+NJzzhCUgkEpiensbTn/70QHpyr9fDG97wBpxyyimIx+M46aST8JrXvAbtdvugdfvSl74Ez/Pw4Q9/GG9605twwgknIJFI4KlPfSruvffeh9Xef/mXf8Ezn/lMzM3NIR6P45RTTsEb3vCGde265557cM0112B2dhaJRAInnHACrr32WpTLZQBDB2K9Xscdd9xxSCnBbMudd96J17zmNZidnUU6ncYv//IvY+/evWOfueuuu3D55ZcjlUph27ZteNvb3rbunsXFRbzoRS/Cli1bkEgkcN555+GOO+4wv99///2Ynp4GANx6662mrrfccou55wtf+AIuueQSpNNpFAoF/Mqv/Ap+9KMfHSpLHTlydBzTodpzYsHb3/52vOtd78KOHTuQTCaxa9cu/OAHPwiU+f3vfx/XX389Tj75ZCQSCczOzuKFL3whVlZWAveN2wuE+0D953/+J570pCchkUjg5JNPxgc/+MHAc7/2a78GALj88suN3dLl3Z/85CeN3cpms3jmM5+JH/7wh+va/4lPfALnnnsuEokEzj33XHz84x8fy6cDBw7g7rvvRrfbPSS+PvnJT8ZTnvIUvO1tb0Oz2TzovYfCr49+9KPwPA//8R//se75v/qrv4LneaYfNtoj7O/+7u9wwQUXIJlMYmJiAtdee+06fOEelN/5zndw6aWXIpVKrXNykX7605+attoUDocxOTlp6vNHf/RHAICdO3ea/mK/P9wxAADccccdiEQipnwA+MY3voGnP/3pyOfzSKVS2LVrF77yla8EnqtWq3jFK16Bk046CfF4HDMzM3ja056G//qv/3rIdzpy5Gjzk8O+Rwf7DkaHYps3okNp16Hy39HmJ+cIc3RMqd/v48orr8Tk5CTe/va3Y9euXXjHO96Bv/7rvw7c96IXvQiveMUrsH37drz1rW/Fq1/9aiQSCXz961839/zWb/0Wbr75Zvzsz/4s3vWud2HXrl14y1vegmuvvfaQ6vJnf/Zn+PjHP45XvvKVuOmmm/D1r38dz3/+8x9Wuz7wgQ8gk8ngxhtvxLvf/W5ccMEFuPnmmwPLTDqdDq688kp8/etfx+///u/jL/7iL/CSl7wE9913n4mAf+hDH0I8Hscll1yCD33oQ/jQhz6E3/7t337I97/pTW/Cv/3bv+GP//iP8fKXvxyf/exnccUVV6ybSJVKJTz96U/Heeedh3e84x0488wz8cd//Mf45Cc/ae5pNpu47LLL8KEPfQjPf/7zcdtttyGfz+P666/Hu9/9bgDA9PQ0/vIv/xIA8Ku/+qumrs961rMAAJ/73Odw5ZVXYnFxEbfccgtuvPFGfPWrX8WTn/zk42p/AkeOHD18OlR7DgAf/OAH8Z73vAcvfelLcdNNN+EHP/gBnvKUp2BhYcHc89nPfhb33XcfbrjhBrz3ve/Ftddei3/6p3/CM57xDPi+/5D1uffee/HsZz8bT3va0/COd7wDxWIR119/vRn0XnrppXj5y18OAHjNa15j7NZZZ50FYGh/n/nMZyKTyeCtb30r/vRP/xR33XUXLr744oDd+sxnPoNrrrkGnufhLW95C66++mrccMMNY/eRuemmm3DWWWdh3759h8zXW265BQsLC8bGbkSHwi+258Mf/vC65++8806cc845Bz1E5U1vehNe8IIX4LTTTsM73/lOvOIVr8DnP/95XHrppesyt1ZWVnDVVVfh/PPPx+23347LL798bJk7duwAAPz93/89er3ehu9+1rOehec973kAgHe9612mvxiEebhjgL/+67/GDTfcgFe/+tW47bbbAAwDN5deeikqlQpe97rX4c1vfjPW1tbwlKc8Bd/85jfNs7/zO7+Dv/zLv8Q111yD973vfXjlK1+JZDLpgjyOHD2OyGHfo4N94+hQbfM4OtR2PVL+O9pE5Dty9Ajpb//2b30A/re+9a0N79m9e7cPwP/bv/1bc+26667zAfivf/3rA/f+zM/8jH/BBReY71/4whd8AP7LX/7ydeUOBgPf933/e9/7ng/A/63f+q3A76985St9AP4XvvAFc23Xrl3+rl27zPcvfvGLPgD/rLPO8tvttrn+7ne/2wfg/8///M8htX/37t3mWqPRWHffb//2b/upVMpvtVq+7/v+d7/7XR+A/5GPfOSg5afTaf+666476D12W7Zt2+ZXKhVz/cMf/rAPwH/3u99tru3atcsH4H/wgx8019rttj87O+tfc8015trtt9/uA/D/7u/+zlzrdDr+RRdd5GcyGfOepaUlH4D/ute9bl29zj//fH9mZsZfWVkx1/77v//bD4VC/gte8IJDapsjR46ODxpn8w/VnhMLksmk/+CDD5rr3/jGN3wA/v/3//1/5to4O/qP//iPPgD/y1/+8rr6qA3esWPHuvsWFxf9eDzu/+Ef/qG59pGPfMQH4H/xi18MvKdarfqFQsF/8YtfHLg+Pz/v5/P5wPXzzz/f37p1q7+2tmaufeYzn/EB+Dt27Ag
|
||
|
"text/plain": [
|
||
|
"<Figure size 1500x1000 with 3 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"lincoln_inpainted_ns = cv.inpaint(src=lincoln, inpaintMask=lincoln_mask, inpaintRadius=5, flags=cv.INPAINT_NS)\n",
|
||
|
"lincoln_inpainted_t = cv.inpaint(src=lincoln, inpaintMask=lincoln_mask, inpaintRadius=5, flags=cv.INPAINT_TELEA)\n",
|
||
|
"\n",
|
||
|
"plt.figure(figsize=(15,10))\n",
|
||
|
"plt.subplot(131)\n",
|
||
|
"plt.imshow(lincoln[:,:,::-1])\n",
|
||
|
"plt.title(\"Lincoln last photo\")\n",
|
||
|
"plt.subplot(132)\n",
|
||
|
"plt.imshow(lincoln_inpainted_ns[:,:,::-1])\n",
|
||
|
"plt.title(\"Inpainted: Navier-Stokes\")\n",
|
||
|
"plt.subplot(133)\n",
|
||
|
"plt.imshow(lincoln_inpainted_t[:,:,::-1])\n",
|
||
|
"plt.title(\"Inpainted: Telea\");"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "62854178",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Transformata Hougha"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "6cc98b55",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Zadanie 1\n",
|
||
|
"\n",
|
||
|
"W poniższym zadaniu należy przygotować serię operacji, która pozwoli wykryć proste linie na obrazie `img/road-lanes.jpg` przy pomocy [transformaty Hougha](https://docs.opencv.org/4.5.3/d9/db0/tutorial_hough_lines.html) (wym. *hafa*), zaimplementowanej w funkcji [`cv.HoughLines()`](https://docs.opencv.org/4.5.3/dd/d1a/group__imgproc__feature.html#ga46b4e588934f6c8dfd509cc6e0e4545a) lub [`cv.HoughLinesP()`](https://docs.opencv.org/4.5.3/dd/d1a/group__imgproc__feature.html#ga8618180a5948286384e3b7ca02f6feeb). Możemy przyjąć, że przetwarzane zdjęcie jest pojedynczą klatką uzyskaną w kamery znajdującej się na jadącym samochodzie.\n",
|
||
|
"\n",
|
||
|
"Kolejne kroki mogą wyglądać następująco:\n",
|
||
|
"\n",
|
||
|
"1. progowanie obrazu w celu uzyskania pasów na drodze,\n",
|
||
|
"2. ograniczenie przetwarzanego obrazu do interesującego nas fragmentu (np. może to być traprez osadzony na dole ekranu zwężający się do środka - góra i boki nas za bardzo nie interesują),\n",
|
||
|
"3. wykrycie krawędzi,\n",
|
||
|
"4. wykrycie linii transformatą Hougha,\n",
|
||
|
"5. ekstrapolacja znalezionych wyżej linii,\n",
|
||
|
"6. naniesienie linii na obraz wejściowy."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 56,
|
||
|
"id": "276ed557",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"<matplotlib.image.AxesImage at 0x25446c9b048>"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 56,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7Tu2d5/THx6gb7D9AaxFsFSFZr0qaZuex+09VX2FLmvMwdBoR60M27t39PsHTHdACRRlSSUV9D3WWMpqjWkt7eHA5volNzc37DvH5vYGW1ToqkIpRdt27PePaHGsNjW7h3e49kCpBHe4wzrN7vBIXSnq7pbPP/+c7eMWXdYocaxXNU5pRBUgBVYEFeSAsygJbfJjDlAAfvEXf5G/+Bf/In/oD/0h/sgf+SP88i//Mo+Pj/ylv/SXLs5DyTCBxK96e/nuEOdwKtZCpuC1gjlvnMVbECK/VUEgZcoCwex+igbf33OriX8cGMton5kDnnPVk5QhHrOezPBHhP7cTAIeKSgHZF/3sofzfg+xb8dYn2HcTAxEZv3vgdZpBpUPt1hAByYdM/yTfTsr//LxeCztuLxhM9CQfBdvro2tHGf6Il+ySFCBZfwRt9EpwOvD6bq6sBw3APFYOIXhN4KUr2kun1qSuWS55pjv19wStAxOjmQKs35abpe4zDzMQNzwIJknTwyJZfYJQmluJSZRLgkWpgQzy0XNFZdxuX/bMl3ztI7UvyvjfQLOCmDANvTtI198+n2ah7e8uKq5ff2CL97s6FsolKYqK1Z1RVWu6NsddVWz2awpV2t2+4auaWmrFq0U69UaozwI6Q97SuUtR33b+2WeHnqr0MWKzbXi5maNrmqkXuF0iXGGoij48MMPEbNCu4bdw1tEmYE3dihKnDGI2bO/P7C7/xzb94it2d0VgKPavGB1/RIpFQ7BivIgRRSIQ5TnL5eGHxlA+fN//s/z+eef8zf/5t/kk08+4Q/8gT/Ar/zKr8wcZ08HjVMenEBY7XIoZ/23JRMrx4F8PmAvcabL08dLSrHAOzoBYg07xOX4ZDhKd6zp5iDlGJ3yNWkZcoIZRYxuKbjo31m2XyNICRrW0lKfm4G6BWAbM/8jYckK4hbeX1qvr9tiNCCms+W
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"\"\"\"\n",
|
||
|
"@file hough_lines.py\n",
|
||
|
"@brief This program demonstrates line finding with the Hough transform\n",
|
||
|
"\"\"\"\n",
|
||
|
"import sys\n",
|
||
|
"import math\n",
|
||
|
"import cv2 as cv\n",
|
||
|
"import numpy as np\n",
|
||
|
"import matplotlib.pyplot as plt\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"default_file = 'img/road-lanes.jpg'\n",
|
||
|
"default_file_mask = 'img/road-lanes-mask.jpg'\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"frame = cv.imread(default_file, cv.IMREAD_COLOR)\n",
|
||
|
"mask = cv.imread(default_file_mask, 0)\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"# image = cv.bitwise_and(res,res,mask = mask)\n",
|
||
|
"gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"kernel_size = 5\n",
|
||
|
"blur = cv.GaussianBlur(gray, (kernel_size, kernel_size), 0)\n",
|
||
|
"\n",
|
||
|
"low_t = 50\n",
|
||
|
"high_t = 150\n",
|
||
|
"edges = cv.Canny(blur, low_t, high_t)\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"vertices = np.array([[(0, edges.shape[0]), (450, 310), (490, 310), (edges.shape[1], edges.shape[0])]], dtype=np.int32)\n",
|
||
|
"mask = np.zeros_like(edges)\n",
|
||
|
"cv.fillPoly(mask, vertices, 255)\n",
|
||
|
"masked_edges = cv.bitwise_and(edges, mask)\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"rho = 3\n",
|
||
|
"theta = np.pi / 180\n",
|
||
|
"threshold = 15\n",
|
||
|
"min_line_len = 150\n",
|
||
|
"max_line_gap = 60\n",
|
||
|
"lines = cv.HoughLinesP(masked_edges, rho, theta, threshold, np.array([]), minLineLength=min_line_len, maxLineGap=max_line_gap)\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"def draw_lines(img, lines, color=[255, 0, 0], thickness=7):\n",
|
||
|
" for line in lines:\n",
|
||
|
" for x1, y1, x2, y2 in line:\n",
|
||
|
" cv.line(img, (x1, y1), (x2, y2), color, thickness)\n",
|
||
|
"\n",
|
||
|
"draw_lines(frame, lines)\n",
|
||
|
"plt.imshow(cv.cvtColor(frame, cv.COLOR_BGR2RGB))\n",
|
||
|
"\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "63a04ced",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"![Pasy wykryte na drodze](img/road-lanes-detected.png)"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"author": "Andrzej Wójtowicz",
|
||
|
"email": "andre@amu.edu.pl",
|
||
|
"kernelspec": {
|
||
|
"display_name": "Python 3.7.12 ('widzenie_komputerowe')",
|
||
|
"language": "python",
|
||
|
"name": "python3"
|
||
|
},
|
||
|
"lang": "pl",
|
||
|
"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.7.12 | packaged by conda-forge | (default, Oct 26 2021, 05:35:01) [MSC v.1916 64 bit (AMD64)]"
|
||
|
},
|
||
|
"subtitle": "04. Zaawansowane przetwarzanie obrazów i fotografia obliczeniowa [laboratoria]",
|
||
|
"title": "Widzenie komputerowe",
|
||
|
"vscode": {
|
||
|
"interpreter": {
|
||
|
"hash": "6ac7fc53e11b5e853f03d2492fedb08fce658edca143f79fa3d2748d3b63b777"
|
||
|
}
|
||
|
},
|
||
|
"year": "2021"
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 5
|
||
|
}
|