test_constrast.ipynb 1.67 KB
Newer Older
Nianchen Deng's avatar
sync    
Nianchen Deng committed
1
2
3
4
{
 "cells": [
  {
   "cell_type": "code",
5
   "execution_count": null,
Nianchen Deng's avatar
sync    
Nianchen Deng committed
6
   "metadata": {},
7
   "outputs": [],
Nianchen Deng's avatar
sync    
Nianchen Deng committed
8
9
10
11
12
13
14
   "source": [
    "import sys\n",
    "import os\n",
    "import torch\n",
    "import matplotlib.pyplot as plt\n",
    "import torchvision.transforms.functional as trans_f\n",
    "\n",
15
16
    "rootdir = os.path.abspath(sys.path[0] + '/../')\n",
    "sys.path.append(rootdir)\n",
Nianchen Deng's avatar
sync    
Nianchen Deng committed
17
18
19
    "torch.cuda.set_device(2)\n",
    "print(\"Set CUDA:%d as current device.\" % torch.cuda.current_device())\n",
    "\n",
Nianchen Deng's avatar
sync    
Nianchen Deng committed
20
21
    "from components import refine\n",
    "from utils import img\n",
Nianchen Deng's avatar
sync    
Nianchen Deng committed
22
    "\n",
23
    "img = img.load(os.path.join(rootdir, \"data/gas_2021.01.04_all_in_one/output/mid_0536.png\"))\n",
Nianchen Deng's avatar
sync    
Nianchen Deng committed
24
25
26
27
28
    "\n",
    "fe = 0.2\n",
    "leng_sigma = [0,3,5]\n",
    "\n",
    "mean, enhanced = refine.constrast_enhance(img, 3, 0.5)\n",
Nianchen Deng's avatar
sync    
Nianchen Deng committed
29
    "img.save(enhanced, \"mid_enhanced.png\")\n",
Nianchen Deng's avatar
sync    
Nianchen Deng committed
30
31
32
    "\n",
    "plt.figure(figsize=(12,12))\n",
    "plt.subplot(121)\n",
Nianchen Deng's avatar
sync    
Nianchen Deng committed
33
    "img.plot(img)\n",
Nianchen Deng's avatar
sync    
Nianchen Deng committed
34
35
36
    "plt.title('Original')\n",
    "plt.axis('off')\n",
    "plt.subplot(122)\n",
Nianchen Deng's avatar
sync    
Nianchen Deng committed
37
    "img.plot(enhanced)\n",
Nianchen Deng's avatar
sync    
Nianchen Deng committed
38
39
40
41
42
43
44
45
46
    "plt.title('Enhanced')\n",
    "plt.axis('off')\n",
    "plt.show()\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
Nianchen Deng's avatar
sync    
Nianchen Deng committed
47
48
   "display_name": "Python 3.7.9 64-bit ('pytorch': conda)",
   "name": "python379jvsc74a57bd0660ca2a75467d3af74a68fcc6f40bc78ab96b99ff17d2f100b5ca821fbb183f2"
Nianchen Deng's avatar
sync    
Nianchen Deng committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  },
  "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.9"
  },
  "orig_nbformat": 2
 },
 "nbformat": 4,
 "nbformat_minor": 2
}