Skip to content

Commit

Permalink
Add fourier and histogram filter classes. Add notebook for histogram …
Browse files Browse the repository at this point in the history
…exploration. Implemented histogram equalisation functionality.
  • Loading branch information
tbsfchnr committed Oct 30, 2020
1 parent 19f20c8 commit c897257
Show file tree
Hide file tree
Showing 5 changed files with 353 additions and 18 deletions.
2 changes: 1 addition & 1 deletion TF00-initial-exploration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"metadata": {},
"outputs": [],
"source": [
"gaus = filters.Gaussian(sig=2)\n",
"gaus = filters.Gaussian(sig=3)\n",
"print(gaus)"
]
},
Expand Down
186 changes: 186 additions & 0 deletions TF01-fourier-exploration.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Fourier 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"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"import modules for debugging"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from math import ceil, floor"
]
},
{
"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": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fourierFilter = filters.FFT_TruncateCoefficients(keep=0.1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"imgFFT = fourierFilter.compute(img, plot=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"handler.plotFigs([img, imgFFT])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"imgFFT2 = np.arange(25).reshape((5,5))\n",
"imgFFT2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Get shape of image: rows and columns\n",
"row, col = imgFFT2.shape\n",
"print(row, col)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"keep = 0.1\n",
"print(keep)\n",
"print(1-keep)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print('imgFFT2[{}:{}, :]'.format(ceil(row*keep), floor(row*(1-keep))))\n",
"print('imgFFT2[:, {}:{}]'.format(ceil(col*keep), floor(col*(1-keep))))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Set all rows and cols to zero not within the keep fraction\n",
"imgFFT2[ceil(row*keep):floor(row*(1-keep)), :] = 0\n",
"imgFFT2[:, ceil(col*keep):floor(col*(1-keep))] = 0"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"imgFFT2"
]
},
{
"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 c897257

Please sign in to comment.