Skip to content

Commit

Permalink
only keeping useful
Browse files Browse the repository at this point in the history
  • Loading branch information
siddiquesalman committed Jun 5, 2023
1 parent 74f7ea4 commit 1374153
Show file tree
Hide file tree
Showing 2 changed files with 227 additions and 106 deletions.
205 changes: 205 additions & 0 deletions .ipynb_checkpoints/flatnet3d_test-checkpoint.ipynb

Large diffs are not rendered by default.

128 changes: 22 additions & 106 deletions flatnet3d_test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,138 +13,54 @@
"import torch\n",
"import scipy.io\n",
"import mat73\n",
"import random\n",
"import torchvision\n",
"import time\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import torchvision.transforms as T\n",
"import torch.nn as nn\n",
"import torch.fft as fft\n",
"import torch.nn.functional as F\n",
"import cv2 as cv\n",
"from PIL import Image\n",
"from skimage import color, data, restoration, img_as_float\n",
"from unet import UNet\n",
"from mpl_toolkits.axes_grid1 import make_axes_locatable\n",
"from pypfm import PFMLoader\n",
"loader = PFMLoader(color=False, compress=False)\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "9de939d7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tested on Torch version: 1.13.1\n"
]
}
],
"source": [
"print(\"tested on Torch version:\",torch.__version__)"
]
},
{
"cell_type": "markdown",
"id": "fad5f90b",
"metadata": {},
"source": [
"### helper functions"
"### load PSFs"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"id": "04899513",
"metadata": {},
"outputs": [],
"source": [
"data_dict_psf = mat73.loadmat('data/psfs_save_magfs.mat')\n",
"psfs = data_dict_psf['psfs'][:,:,:,-25:][::2,::2]\n",
"\n",
"def show_figure(image1, title1, mode=\"single\", image2=None, title2=None, save=False, img_name=None, cmap='gray'):\n",
" \n",
" if mode=='single':\n",
" fig = plt.figure()\n",
" plt.axis('off')\n",
" plt.imshow(image1, cmap=cmap)\n",
" \n",
" if mode=='single-colorbar':\n",
" fig, ax = plt.subplots()\n",
" divider = make_axes_locatable(ax)\n",
" cax = divider.append_axes('right', size='5%', pad=0.2)\n",
"\n",
" im1 = ax.imshow(image1, cmap=cmap)\n",
" ax.set_title(title1)\n",
"\n",
" fig.colorbar(im1, cax=cax, orientation='vertical')\n",
" \n",
" elif mode=='comparison':\n",
" fig, (ax1, ax2) = plt.subplots(1, 2)\n",
" divider = make_axes_locatable(ax1)\n",
" cax = divider.append_axes('right', size='5%', pad=0.2)\n",
"\n",
" im1 = ax1.imshow(image1, cmap=cmap)\n",
" ax1.set_title(title1)\n",
"\n",
" fig.colorbar(im1, cax=cax, orientation='vertical')\n",
" \n",
" divider = make_axes_locatable(ax2)\n",
" cax = divider.append_axes('right', size='5%', pad=0.2)\n",
"\n",
" im2 = ax2.imshow(image2, cmap=cmap)\n",
" ax2.set_title(title2)\n",
"\n",
" fig.colorbar(im2, cax=cax, orientation='vertical')\n",
" fig.tight_layout(pad=1.0)\n",
" fig.show()\n",
" \n",
" if save:\n",
" fig.savefig(img_name)\n",
"\n",
" \n",
"from struct import *\n",
"def load_pfm(file_path):\n",
" \"\"\"\n",
" load image in PFM type.\n",
" Args:\n",
" file_path string: file path(absolute)\n",
" Returns:\n",
" data (numpy.array): data of image in (Height, Width[, 3]) layout\n",
" scale (float): scale of image\n",
" \"\"\"\n",
" with open(file_path, encoding=\"ISO-8859-1\") as fp:\n",
" color = None\n",
" width = None\n",
" height = None\n",
" scale = None\n",
" endian = None\n",
"\n",
" # load file header and grab channels, if is 'PF' 3 channels else 1 channel(gray scale)\n",
" header = fp.readline().rstrip()\n",
" if header == 'PF':\n",
" color = True\n",
" elif header == 'Pf':\n",
" color = False\n",
" else:\n",
" raise Exception('Not a PFM file.')\n",
"\n",
" # grab image dimensions\n",
" dim_match = re.match(r'^(\\d+)\\s(\\d+)\\s$', fp.readline())\n",
" if dim_match:\n",
" width, height = map(int, dim_match.groups())\n",
" else:\n",
" raise Exception('Malformed PFM header.')\n",
"\n",
" # grab image scale\n",
" scale = float(fp.readline().rstrip())\n",
" if scale < 0: # little-endian\n",
" endian = '<'\n",
" scale = -scale\n",
" else:\n",
" endian = '>' # big-endian\n",
"\n",
" # grab image data\n",
" data = np.fromfile(fp, endian + 'f')\n",
" shape = (height, width, 3) if color else (height, width)\n",
"\n",
" # reshape data to [Height, Width, Channels]\n",
" data = np.reshape(data, shape)\n",
" data = np.flipud(data)\n",
"\n",
" return data\n",
"\n",
"\n",
" \n",
"## AIF metrics; gt, recon must be scaled from 0-1, dim:(128, 128, 3)\n"
"psfs = data_dict_psf['psfs'][:,:,:,-25:][::2,::2]\n"
]
},
{
Expand All @@ -157,7 +73,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"id": "2157dcf3",
"metadata": {},
"outputs": [
Expand Down

0 comments on commit 1374153

Please sign in to comment.