{"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.12.12"},"kaggle":{"accelerator":"none","dataSources":[{"sourceType":"competition","sourceId":129543,"databundleVersionId":15525987,"isSourceIdPinned":false}],"dockerImageVersionId":31286,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false},"papermill":{"default_parameters":{},"duration":3.895092,"end_time":"2026-03-08T13:47:59.502585","environment_variables":{},"exception":null,"input_path":"__notebook__.ipynb","output_path":"__notebook__.ipynb","parameters":{},"start_time":"2026-03-08T13:47:55.607493","version":"2.6.0"}},"nbformat_minor":4,"nbformat":4,"cells":[{"id":"51397a3c","cell_type":"code","source":"from PIL import Image\nimport numpy as np\n\noriginal_image = Image.open(\"/kaggle/input/competitions/round-2-jaguar-reidentification-challenge/train/train_0014.png\")\noriginal_image","metadata":{"_cell_guid":"2f2b87cb-20ba-4b80-97ee-d6e0a9982ca5","_uuid":"b971f026-855f-49a2-94c8-b6efcc13b62e","collapsed":false,"execution":{"iopub.status.busy":"2026-03-10T21:45:46.490250Z","iopub.execute_input":"2026-03-10T21:45:46.491427Z","iopub.status.idle":"2026-03-10T21:45:46.890292Z","shell.execute_reply.started":"2026-03-10T21:45:46.491378Z","shell.execute_reply":"2026-03-10T21:45:46.888959Z"},"jupyter":{"outputs_hidden":false},"papermill":{"duration":0.205524,"end_time":"2026-03-08T13:47:58.752645","exception":false,"start_time":"2026-03-08T13:47:58.547121","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"e5b9c8cb","cell_type":"code","source":"np.array(original_image).shape","metadata":{"_cell_guid":"a0edb981-a408-45d4-be26-5c4accfda198","_uuid":"87d5a296-2a4c-4e79-b9ad-a7f94c6100e7","collapsed":false,"execution":{"iopub.status.busy":"2026-03-10T21:45:46.892992Z","iopub.execute_input":"2026-03-10T21:45:46.893745Z","iopub.status.idle":"2026-03-10T21:45:46.915508Z","shell.execute_reply.started":"2026-03-10T21:45:46.893707Z","shell.execute_reply":"2026-03-10T21:45:46.914563Z"},"jupyter":{"outputs_hidden":false},"papermill":{"duration":0.022273,"end_time":"2026-03-08T13:47:58.786901","exception":false,"start_time":"2026-03-08T13:47:58.764628","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"8a7bcb50","cell_type":"code","source":"# Note that the \"round 2\" images include no background information\nrgb_image = original_image.convert(\"RGB\")\nrgb_image","metadata":{"_cell_guid":"52579e24-1026-4a2a-961b-29f160c8a50f","_uuid":"38b9ea05-8900-40f4-a9a1-9dde23c4ff36","collapsed":false,"execution":{"iopub.status.busy":"2026-03-10T21:45:46.916813Z","iopub.execute_input":"2026-03-10T21:45:46.917154Z","iopub.status.idle":"2026-03-10T21:45:47.217357Z","shell.execute_reply.started":"2026-03-10T21:45:46.917119Z","shell.execute_reply":"2026-03-10T21:45:47.215955Z"},"jupyter":{"outputs_hidden":false},"papermill":{"duration":0.115441,"end_time":"2026-03-08T13:47:58.915205","exception":false,"start_time":"2026-03-08T13:47:58.799764","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"36f9dceb","cell_type":"code","source":"np.array(rgb_image).shape","metadata":{"_cell_guid":"60d641d0-78cf-4df4-8bca-1a7b8d11e811","_uuid":"701d86c1-3a73-4f3d-82b2-197a318fb85a","collapsed":false,"execution":{"iopub.status.busy":"2026-03-10T21:45:47.219961Z","iopub.execute_input":"2026-03-10T21:45:47.220413Z","iopub.status.idle":"2026-03-10T21:45:47.239644Z","shell.execute_reply.started":"2026-03-10T21:45:47.220368Z","shell.execute_reply":"2026-03-10T21:45:47.238573Z"},"jupyter":{"outputs_hidden":false},"papermill":{"duration":0.029583,"end_time":"2026-03-08T13:47:58.966506","exception":false,"start_time":"2026-03-08T13:47:58.936923","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"729e5460","cell_type":"code","source":"alpha_mask = np.array(original_image)[:, :, 3]\nImage.fromarray(alpha_mask)","metadata":{"_cell_guid":"475a69a3-40c4-434b-8cc2-24e0e0944c5a","_uuid":"8907574b-1f01-49ee-9489-8a47b9dcd1f3","collapsed":false,"execution":{"iopub.status.busy":"2026-03-10T21:45:47.240808Z","iopub.execute_input":"2026-03-10T21:45:47.241681Z","iopub.status.idle":"2026-03-10T21:45:47.312826Z","shell.execute_reply.started":"2026-03-10T21:45:47.241644Z","shell.execute_reply":"2026-03-10T21:45:47.311807Z"},"jupyter":{"outputs_hidden":false},"papermill":{"duration":0.038286,"end_time":"2026-03-08T13:47:59.025835","exception":false,"start_time":"2026-03-08T13:47:58.987549","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"44cb4fa9","cell_type":"code","source":"img = np.array(original_image)\nrgb = img[:, :, :3].astype(np.float32)\nalpha = img[:, :, 3].astype(np.float32) / 255.0\n\ncutout_rgb = (rgb * alpha[..., None]).astype(np.uint8)\nImage.fromarray(cutout_rgb)","metadata":{"_cell_guid":"6caa3636-8852-4436-b30b-f17fedfea6ee","_uuid":"3f87f034-9715-4014-bb35-cb4c0d251c4d","collapsed":false,"execution":{"iopub.status.busy":"2026-03-10T21:45:47.314371Z","iopub.execute_input":"2026-03-10T21:45:47.314709Z","iopub.status.idle":"2026-03-10T21:45:47.631102Z","shell.execute_reply.started":"2026-03-10T21:45:47.314675Z","shell.execute_reply":"2026-03-10T21:45:47.628843Z"},"jupyter":{"outputs_hidden":false},"papermill":{"duration":0.106756,"end_time":"2026-03-08T13:47:59.155905","exception":false,"start_time":"2026-03-08T13:47:59.049149","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null}]}