Skip to content

Commit

Permalink
Final results generated in notebooks. Small changes to code.
Browse files Browse the repository at this point in the history
  • Loading branch information
tbsfchnr committed Nov 24, 2020
1 parent 25e5fe3 commit 96cf3b0
Show file tree
Hide file tree
Showing 11 changed files with 1,273 additions and 174 deletions.
49 changes: 10 additions & 39 deletions TF00-initial-exploration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,10 @@
"metadata": {},
"outputs": [],
"source": [
"meanie = filters.Mean(maskSize=5)\n",
"print(meanie)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"imgFiltered = meanie.convolve(img)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"handler.plotFigs([img, imgFiltered])"
"for maskSize in [3,5,7,9,11,21,51]:\n",
" meanie = filters.Mean(maskSize=maskSize)\n",
" imgFiltered = meanie.convolve(img)\n",
" handler.plotFigs([img, imgFiltered], meanie)"
]
},
{
Expand Down Expand Up @@ -338,25 +322,12 @@
"metadata": {},
"outputs": [],
"source": [
"trimmedMean = filters.TrimmedMean(maskSize=5, trimStart=4, trimEnd=4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"imgFiltered = trimmedMean.convolve(img)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"handler.plotFigs([img, imgFiltered])"
"for maskSize in [3,5,7,9,11,21,51]:\n",
" for trim in [maskSize, maskSize*2, maskSize*3]:\n",
" trimmedMean = filters.TrimmedMean(maskSize=5, trimStart=4, trimEnd=4)\n",
" imgFiltered = trimmedMean.convolve(img)\n",
" filteredTitle = trimmedMean.name + \"_maskSize\" + str(trimmedMean.maskSize) + \"_trim\" + str(trim)\n",
" handler.plotFigs([img, imgFiltered], trimmedMean, filteredTitle)"
]
},
{
Expand Down
65 changes: 6 additions & 59 deletions TF02-histogram-exploration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"metadata": {},
"outputs": [],
"source": [
"filtr = filters.Equalise()"
"eq = filters.Equalise()"
]
},
{
Expand All @@ -74,7 +74,7 @@
"metadata": {},
"outputs": [],
"source": [
"imgNew = filtr.filter(img)"
"imgNew = eq.filter(img)"
]
},
{
Expand All @@ -83,7 +83,7 @@
"metadata": {},
"outputs": [],
"source": [
"handler.plotFigs([img, imgNew])"
"handler.plotFigs([img, imgNew], eq, filteredTitle=eq.name)"
]
},
{
Expand All @@ -99,7 +99,7 @@
"metadata": {},
"outputs": [],
"source": [
"filtr = filters.AHE(maskSize=126)"
"ahe = filters.AHE(maskSize=21)"
]
},
{
Expand All @@ -108,7 +108,7 @@
"metadata": {},
"outputs": [],
"source": [
"imgNew = filtr.filter(img)"
"imgNew = ahe.filter(img)"
]
},
{
Expand All @@ -117,60 +117,7 @@
"metadata": {},
"outputs": [],
"source": [
"handler.plotFigs([img, imgNew])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Save Results"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n",
"import os.path\n",
"from PIL import Image"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"currentDir = Path().absolute()\n",
"root = str(currentDir) + '\\\\..\\outputs\\\\hist_Adaptive_Equalise\\\\'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if not os.path.exists(root):\n",
" os.makedirs(root)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Create pillow image object from filtered image array\n",
"img_PIL = Image.fromarray(imgNew, 'L')\n",
"\n",
"# Save filtered image from pillow image object\n",
"filePath = root+'filtered_foetus_maskSize_126.png'\n",
"img_PIL.save(filePath, 'PNG')\n",
"print(\"Saved filtered image to... \\n{}\\n\\n\".format(filePath))"
"handler.plotFigs([img, imgNew], ahe)"
]
},
{
Expand Down
221 changes: 221 additions & 0 deletions TF03-histogram-exploration-sliding-window.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Histogram Exploration"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Imports"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import filters\n",
"import handler"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np # for debugging purposes\n",
"import matplotlib.pyplot as plt\n",
"from sklearn.preprocessing import normalize\n",
"from math import ceil"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Load Image"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"img, _ = handler.getImageAsArray(handler.FOETUS_PATH_ORIGINAL)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Create and Apply SWAHE Filter"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"swahe = filters.SWAHE(maskSize = 127)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"imgNew = swahe.filter(img)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"handler.plotFigs([img, imgNew], swahe)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"img.shape"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Save Results"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n",
"import os.path\n",
"from PIL import Image"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"currentDir = Path().absolute()\n",
"root = str(currentDir) + '\\\\..\\outputs\\\\hist_Adaptive_Equalise\\\\'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if not os.path.exists(root):\n",
" os.makedirs(root)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Create pillow image object from filtered image array\n",
"img_PIL = Image.fromarray(imgNew[0], 'L')\n",
"\n",
"# Save filtered image from pillow image object\n",
"filePath = root+'filtered_foetus_maskSize_52.png'\n",
"img_PIL.save(filePath, 'PNG')\n",
"print(\"Saved filtered image to... \\n{}\\n\\n\".format(filePath))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 3rd Part Check"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use CV2 library built-in equalise and CLAHe functions."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import third_party_filters"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"third_party_filters.equalise(handler.FOETUS_PATH_ORIGINAL)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"third_party_filters.CLAHE(handler.FOETUS_PATH_ORIGINAL)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.8.1"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading

0 comments on commit 96cf3b0

Please sign in to comment.