{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"! pip install git+https://github.com/histolab/histolab","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-09-16T13:17:31.910192Z","iopub.execute_input":"2022-09-16T13:17:31.911261Z","iopub.status.idle":"2022-09-16T13:18:13.771537Z","shell.execute_reply.started":"2022-09-16T13:17:31.911113Z","shell.execute_reply":"2022-09-16T13:18:13.769639Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! pip install git+https://github.com/yu4u/seam-carving.git","metadata":{"execution":{"iopub.status.busy":"2022-09-16T13:18:18.098932Z","iopub.execute_input":"2022-09-16T13:18:18.099473Z","iopub.status.idle":"2022-09-16T13:18:33.255853Z","shell.execute_reply.started":"2022-09-16T13:18:18.099427Z","shell.execute_reply":"2022-09-16T13:18:33.254719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from pathlib import Path\nfrom PIL import Image\nImage.MAX_IMAGE_PIXELS = None\nimport matplotlib.pyplot as plt\nimport seam_carving\nseam_carving.carve.MAX_MEAN_ENERGY = 10.0","metadata":{"execution":{"iopub.status.busy":"2022-09-16T13:18:45.88241Z","iopub.execute_input":"2022-09-16T13:18:45.882838Z","iopub.status.idle":"2022-09-16T13:18:46.0061Z","shell.execute_reply.started":"2022-09-16T13:18:45.882797Z","shell.execute_reply":"2022-09-16T13:18:46.004417Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from histolab.slide import Slide\nfrom histolab.tiler import ScoreTiler\nfrom histolab.scorer import NucleiScorer\nimport os\n\nBASE_PATH = os.getcwd()\nCRC_path='../input/mayo-clinic-strip-ai/train/008e5c_0.tif'#图片位置\n#path=r\"./picturecut\"#切割完成后图片存放的位置\n#CRC_slide = Slide(CRC_path,processed_path=path)","metadata":{"execution":{"iopub.status.busy":"2022-09-16T13:18:59.188505Z","iopub.execute_input":"2022-09-16T13:18:59.188934Z","iopub.status.idle":"2022-09-16T13:19:00.890276Z","shell.execute_reply.started":"2022-09-16T13:18:59.188899Z","shell.execute_reply":"2022-09-16T13:19:00.888677Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"CRC_path2 = r\"./pic.tif\"  \npath=r\"./picturecut\"#切割完成后图片存放的位置\n\nimg = Image.open(CRC_path)\nimg.thumbnail((2048, 2048))\ndst = seam_carving.resize(img, (512, 512))\ndst2 = Image.fromarray(dst)\ndst2.save(CRC_path2)\n#fig = plt.figure(figsize=(12, 12))\n#ax = fig.add_subplot(1, 2, 1)\n#ax.set_title(f\"{CRC_path.stem} original\")\n#ax.imshow(img)\n#ax = fig.add_subplot(1, 2, 2)\n#ax.set_title(f\"{CRC_path.stem} resized\")\n#ax.imshow(dst)\n#fig.show()\n\nCRC_slide = Slide(CRC_path2,processed_path=path)","metadata":{"execution":{"iopub.status.busy":"2022-09-16T13:30:49.047503Z","iopub.execute_input":"2022-09-16T13:30:49.048339Z","iopub.status.idle":"2022-09-16T13:31:03.159183Z","shell.execute_reply.started":"2022-09-16T13:30:49.048274Z","shell.execute_reply":"2022-09-16T13:31:03.157205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scored_tiles_extractor = ScoreTiler(\n    scorer = NucleiScorer(),\n    tile_size=(128, 128),\n    n_tiles=100,\n    level=0,\n    check_tissue=True,\n    tissue_percent=80.0,\n    pixel_overlap=0, # default\n    prefix=\"scored/\", # save tiles in the \"scored\" subdirectory of slide's processed_path\n    suffix=\".png\" # default\n)","metadata":{"execution":{"iopub.status.busy":"2022-09-16T13:29:03.769374Z","iopub.execute_input":"2022-09-16T13:29:03.769876Z","iopub.status.idle":"2022-09-16T13:29:03.776908Z","shell.execute_reply.started":"2022-09-16T13:29:03.769842Z","shell.execute_reply":"2022-09-16T13:29:03.775625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scored_tiles_extractor.locate_tiles(slide=CRC_slide)","metadata":{"execution":{"iopub.status.busy":"2022-09-16T13:29:06.102602Z","iopub.execute_input":"2022-09-16T13:29:06.103466Z","iopub.status.idle":"2022-09-16T13:29:07.029146Z","shell.execute_reply.started":"2022-09-16T13:29:06.103426Z","shell.execute_reply":"2022-09-16T13:29:07.027675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"summary_filename = \"summary_ovarian_tiles.csv\"\nSUMMARY_PATH = os.path.join(CRC_slide.processed_path, summary_filename)\n\nscored_tiles_extractor.extract(CRC_slide, report_path=SUMMARY_PATH)","metadata":{"execution":{"iopub.status.busy":"2022-09-16T13:26:44.233164Z","iopub.execute_input":"2022-09-16T13:26:44.233647Z","iopub.status.idle":"2022-09-16T13:26:44.814037Z","shell.execute_reply.started":"2022-09-16T13:26:44.233613Z","shell.execute_reply":"2022-09-16T13:26:44.812629Z"},"trusted":true},"execution_count":null,"outputs":[]}]}