Skip to content

Commit

Permalink
fixing some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
NadiaBlostein committed May 5, 2023
1 parent d911cac commit e278178
Showing 1 changed file with 42 additions and 57 deletions.
99 changes: 42 additions & 57 deletions PNG_preparation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,6 @@
"- Note that here, the default colour map of the 1-tensor images is actually the viridis _cmap_ (yellow to dark purple), which is unexpected. This is a great example of why you should always check the dimensions of the image array, and never trust your naked eye alone!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's first try to fix the issue of having different tensor dimensions by converting every image numpy array to a 1-tensor (i.e. convert the rbg pixel value encoding to a grayscale pixel value encoding):"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -209,19 +202,11 @@
"\n",
"images_adjusted = []\n",
"for i in range(20):\n",
" img=images[i]\n",
" grayscale=rgb2gray(img)\n",
" images_adjusted.append(grayscale)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
" img = images[i]\n",
" if len(img.shape) != 2:\n",
" grayscale=rgb2gray(img)\n",
" images_adjusted.append(grayscale)\n",
"\n",
"fig = plt.figure(figsize=(20, 15))\n",
"rows = 5\n",
"columns = 4\n",
Expand Down Expand Up @@ -315,16 +300,16 @@
"metadata": {},
"outputs": [],
"source": [
"resized_images=[]\n",
"fig = plt.figure(figsize=(20, 15))\n",
"rows = 5\n",
"columns = 4\n",
"for i in range(20):\n",
" fig.add_subplot(rows, columns, i+1)\n",
" img=resized_images_array[i]\n",
" plt.imshow(img)\n",
" plt.axis('off')\n",
" plt.title(img.shape)"
"# resized_images=[]\n",
"# fig = plt.figure(figsize=(20, 15))\n",
"# rows = 5\n",
"# columns = 4\n",
"# for i in range(20):\n",
"# fig.add_subplot(rows, columns, i+1)\n",
"# img=resized_images_array[i]\n",
"# plt.imshow(img)\n",
"# plt.axis('off')\n",
"# plt.title(img.shape)"
]
},
{
Expand All @@ -341,14 +326,14 @@
"metadata": {},
"outputs": [],
"source": [
"height=[]\n",
"width=[]\n",
"for i in range(20):\n",
" img=images_adjusted[i]\n",
" height.append(img.shape[0])\n",
" width.append(img.shape[1])\n",
"print(f'Smallest image height: {min(height)}')\n",
"print(f'Smallest image width: {min(width)}')"
"# height=[]\n",
"# width=[]\n",
"# for i in range(20):\n",
"# img=images_adjusted[i]\n",
"# height.append(img.shape[0])\n",
"# width.append(img.shape[1])\n",
"# print(f'Smallest image height: {min(height)}')\n",
"# print(f'Smallest image width: {min(width)}')"
]
},
{
Expand All @@ -357,13 +342,13 @@
"metadata": {},
"outputs": [],
"source": [
"trimmed_images=[]\n",
"for i in range(20):\n",
" img=images_adjusted[i]\n",
" img_trim=img[0:min(height),0:min(width)]\n",
" trimmed_images.append(img_trim)\n",
"trimmed_images_array = np.array(trimmed_images)\n",
"trimmed_images_array.shape"
"# trimmed_images=[]\n",
"# for i in range(20):\n",
"# img=images_adjusted[i]\n",
"# img_trim=img[0:min(height),0:min(width)]\n",
"# trimmed_images.append(img_trim)\n",
"# trimmed_images_array = np.array(trimmed_images)\n",
"# trimmed_images_array.shape"
]
},
{
Expand All @@ -372,15 +357,15 @@
"metadata": {},
"outputs": [],
"source": [
"fig = plt.figure(figsize=(20, 15))\n",
"rows = 5\n",
"columns = 4\n",
"for i in range(20):\n",
" fig.add_subplot(rows, columns, i+1)\n",
" img=trimmed_images_array[i]\n",
" plt.imshow(img)\n",
" plt.axis('off')\n",
" plt.title(img.shape)"
"# fig = plt.figure(figsize=(20, 15))\n",
"# rows = 5\n",
"# columns = 4\n",
"# for i in range(20):\n",
"# fig.add_subplot(rows, columns, i+1)\n",
"# img=trimmed_images_array[i]\n",
"# plt.imshow(img)\n",
"# plt.axis('off')\n",
"# plt.title(img.shape)"
]
},
{
Expand Down Expand Up @@ -434,7 +419,7 @@
"import matplotlib\n",
"\n",
"for i in range(20):\n",
" img=images_adjusted[i]\n",
" img = images_adjusted[i]\n",
" matplotlib.image.imsave(f'adjusted_images/img_{i}.png', img) "
]
},
Expand Down Expand Up @@ -648,7 +633,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -662,7 +647,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.8.13"
}
},
"nbformat": 4,
Expand Down

0 comments on commit e278178

Please sign in to comment.