Skip to content

Commit

Permalink
Merge pull request #2 from Tobias-Fechner/002-advanced-filters
Browse files Browse the repository at this point in the history
002 advanced filters
  • Loading branch information
tbsfchnr authored Nov 25, 2020
2 parents 365d973 + c407ff3 commit 6210391
Show file tree
Hide file tree
Showing 11 changed files with 1,542 additions and 456 deletions.
104 changes: 84 additions & 20 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 @@ -275,6 +259,86 @@
"handler.saveAll(imgFiltered, lowP)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create and Apply Adaptive Weighted Median Filter"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"awMed = filters.AdaptiveWeightedMedian(maskSize=7, constant=20, centralWeight=100)\n",
"print(awMed)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"imgFiltered = awMed.convolve(img)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"handler.plotFigs([img, imgFiltered])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"handler.saveAll(imgFiltered, awMed)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create and Apply Trimmed Mean Filter"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"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)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"handler.saveAll(imgFiltered, trimmedMean)"
]
},
{
"cell_type": "code",
"execution_count": null,
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
Loading

0 comments on commit 6210391

Please sign in to comment.