154 lines
4.1 KiB
Text
154 lines
4.1 KiB
Text
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 19,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import os\n",
|
|
"\n",
|
|
"from PIL import Image, ImageFilter, ImageMath\n",
|
|
"\n",
|
|
"import numpy as np\n",
|
|
"import skimage\n",
|
|
"from sklearn.feature_extraction import image\n",
|
|
"\n",
|
|
"STUDY_PATH = \"/media/cifs/shares/SRS/storage/tmp/MRI With_Without Contrast--Brain_53820330\"\n",
|
|
"\n",
|
|
"MODEL_PATH = '/home/xfr/nni/model-5-64/TwNuKtj7/best_zdoyO.pth'\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 20,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"/media/cifs/shares/SRS/storage/tmp/MRI With_Without Contrast--Brain_53820330/export--873570386.jpg\n",
|
|
"<PIL.Image.Image image mode=L size=512x512 at 0x7FE087FC8350>\n",
|
|
"[[34 34 32 ... 35 34 33]\n",
|
|
" [34 43 40 ... 45 40 42]\n",
|
|
" [29 49 47 ... 42 39 47]\n",
|
|
" ...\n",
|
|
" [31 48 49 ... 45 42 41]\n",
|
|
" [33 51 49 ... 43 48 54]\n",
|
|
" [36 56 52 ... 61 58 60]]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"for jpg_file in sorted(os.listdir(STUDY_PATH)):\n",
|
|
" jpg_path = os.path.join(STUDY_PATH, jpg_file)\n",
|
|
" print(jpg_path)\n",
|
|
" img = Image.open(jpg_path).convert('L')\n",
|
|
" print(img)\n",
|
|
" data = np.array(img)\n",
|
|
" print(data)\n",
|
|
" \n",
|
|
"# blocks = skimage.util.shape.view_as_blocks(data, (300, 300))\n",
|
|
"# print(blocks.shape)\n",
|
|
" \n",
|
|
" break"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 26,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"['BaseEstimator', 'PatchExtractor', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_compute_gradient_3d', '_compute_n_patches', '_make_edges_3d', '_mask_edges_weights', '_to_graph', 'as_strided', 'check_array', 'check_random_state', 'extract_patches', 'extract_patches_2d', 'grid_to_graph', 'img_to_graph', 'np', 'numbers', 'product', 'reconstruct_from_patches_2d', 'sparse']\n",
|
|
"(2, 2, 250, 250)\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(dir(image))\n",
|
|
"# extract_patches\n",
|
|
"\n",
|
|
"patches = image.extract_patches(data, patch_shape=250, extraction_step=250)\n",
|
|
"print(patches.shape)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 25,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"(512, 512)\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(data.shape)\n",
|
|
"\n",
|
|
"\n",
|
|
"# # chop it up\n",
|
|
"# I, J = map(np.arange, (200, 200), data.shape[:2], (200, 200))\n",
|
|
"# chops = [np.split(row, J, axis=1) for row in np.split(data, I, axis=0)]\n",
|
|
"\n",
|
|
"# print(I,J)\n",
|
|
"# print(len(chops))\n",
|
|
"# print(chops[0])\n",
|
|
"# # do something with the bits\n",
|
|
"\n",
|
|
"# predictions = [chop-(i+j)*(chop>>3) for j, row in enumerate(chops) for i, chop in enumerate(row)]\n",
|
|
"\n",
|
|
"# # unflatten predictions\n",
|
|
"# def nest(data, template):\n",
|
|
"# data = iter(data)\n",
|
|
"# return [[next(data) for _ in row] for row in template]\n",
|
|
"\n",
|
|
"# pred_lol = nest(predictions, chops)\n",
|
|
"\n",
|
|
"\n",
|
|
"# # almost builtin reconstruction\n",
|
|
"# def np_block_2D(chops):\n",
|
|
"# return np.block([[[x] for x in row] for row in chops])\n",
|
|
"\n",
|
|
"# recon = np_block_2D(pred_lol)\n",
|
|
"# Image.fromarray(recon).save('demo.png')"
|
|
]
|
|
},
|
|
{
|
|
"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.7.4"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|