{"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":"markdown","source":"# Test 38280 tấm sai 3 tấm ","metadata":{"_kg_hide-output":false}},{"cell_type":"markdown","source":"40317_840036202\n\n23225_535757590\n\n23225_1886103807","metadata":{}},{"cell_type":"markdown","source":"Đúng 99.99% trong tổng số 38280 tấm","metadata":{"execution":{"iopub.status.busy":"2023-02-24T08:03:38.773287Z","iopub.execute_input":"2023-02-24T08:03:38.773999Z","iopub.status.idle":"2023-02-24T08:03:38.780187Z","shell.execute_reply.started":"2023-02-24T08:03:38.773965Z","shell.execute_reply":"2023-02-24T08:03:38.778804Z"}}},{"cell_type":"code","source":"### Thời gian trung bình sửa lý trong 1 tấm \nper = round(43200 / 38280, 2)\nprint(f'Tổng thời gian xử lý trong một tấm {per} %')\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2023-02-25T08:34:06.982424Z","iopub.execute_input":"2023-02-25T08:34:06.982896Z","iopub.status.idle":"2023-02-25T08:34:07.014115Z","shell.execute_reply.started":"2023-02-25T08:34:06.982803Z","shell.execute_reply":"2023-02-25T08:34:07.012957Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\n\ndata = pd.Series([1, 2, 3, ..., 38279, 38280])\npercent = 100 - (data.value_counts()[3] / len(data)) * 100\nprint(\"Phần trăm số 3 trong tập dữ liệu là:\", percent, \"%\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2023-02-25T08:34:07.016218Z","iopub.execute_input":"2023-02-25T08:34:07.016842Z","iopub.status.idle":"2023-02-25T08:34:07.038191Z","shell.execute_reply.started":"2023-02-25T08:34:07.01681Z","shell.execute_reply":"2023-02-25T08:34:07.03735Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_image = pd.read_csv('/kaggle/input/rsna-breast-cancer-detection/train.csv')\ndata_image.head(10)","metadata":{"execution":{"iopub.status.busy":"2023-02-25T08:34:07.039433Z","iopub.execute_input":"2023-02-25T08:34:07.039947Z","iopub.status.idle":"2023-02-25T08:34:07.182237Z","shell.execute_reply.started":"2023-02-25T08:34:07.039917Z","shell.execute_reply":"2023-02-25T08:34:07.181418Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_image.loc[data_image['image_id'].isin([840036202,535757590,  1886103807, 96888113])]","metadata":{"execution":{"iopub.status.busy":"2023-02-25T08:34:07.183464Z","iopub.execute_input":"2023-02-25T08:34:07.183947Z","iopub.status.idle":"2023-02-25T08:34:07.208172Z","shell.execute_reply.started":"2023-02-25T08:34:07.183915Z","shell.execute_reply":"2023-02-25T08:34:07.207014Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"00:13 Nhập xét khí sài  mean có vẽ đúng hơn median","metadata":{}},{"cell_type":"code","source":"!pip install -qU python-gdcm pydicom pylibjpeg\n!pip install -U pylibjpeg-libjpeg -v\n!pip install pylibjpeg pylibjpeg-libjpeg pylibjpeg-openjpeg\n!pip install pydicom","metadata":{"execution":{"iopub.status.busy":"2023-02-25T08:34:09.926194Z","iopub.execute_input":"2023-02-25T08:34:09.926837Z","iopub.status.idle":"2023-02-25T08:34:59.431149Z","shell.execute_reply.started":"2023-02-25T08:34:09.926801Z","shell.execute_reply":"2023-02-25T08:34:59.429685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n# import include nesscessary\nimport cv2\nfrom PIL import Image, ImageOps\nimport argparse\nimport os\nimport glob\nimport matplotlib.pyplot as plt\nimport multiprocessing as mp\nfrom joblib import Parallel, delayed\nimport pydicom\nimport time\nimport numpy as np\nimport torch\nimport random\nimport pandas as pd\nfrom pydicom.pixel_data_handlers import apply_windowing\nimport imageio\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-02-25T08:34:07.211273Z","iopub.execute_input":"2023-02-25T08:34:07.211765Z","iopub.status.idle":"2023-02-25T08:34:09.924933Z","shell.execute_reply.started":"2023-02-25T08:34:07.211719Z","shell.execute_reply":"2023-02-25T08:34:09.92377Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def trimmed_mean(data, alpha):\n    n = len(data)\n    k = int(round(alpha*n/2))\n    return np.mean(sorted(data)[k:-k])","metadata":{"execution":{"iopub.status.busy":"2023-02-25T08:34:59.434198Z","iopub.execute_input":"2023-02-25T08:34:59.434747Z","iopub.status.idle":"2023-02-25T08:34:59.443582Z","shell.execute_reply.started":"2023-02-25T08:34:59.434696Z","shell.execute_reply":"2023-02-25T08:34:59.442392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# cnt = 0","metadata":{"execution":{"iopub.status.busy":"2023-02-25T08:35:02.124937Z","iopub.execute_input":"2023-02-25T08:35:02.126034Z","iopub.status.idle":"2023-02-25T08:35:02.131492Z","shell.execute_reply.started":"2023-02-25T08:35:02.125976Z","shell.execute_reply":"2023-02-25T08:35:02.129798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def find_id_max(numLabels, labels, stats, centroids, thresh):\n    idmax = 0\n    total = np.sum(thresh)\n    sum_pixel = total/4\n#     print(total)\n    density_ar = total/(thresh.shape[0]*thresh.shape[1]);\n#     print(f'Total density: {density_ar}')\n    for i in range(0, numLabels): \n        x = stats[i, cv2.CC_STAT_LEFT] \n        y = stats[i, cv2.CC_STAT_TOP] \n        w = stats[i, cv2.CC_STAT_WIDTH] \n        h = stats[i, cv2.CC_STAT_HEIGHT] \n#         if x + w == thresh.shape[1] and y + h ==  thresh.shape[0]:\n#             continue\n        sums = np.sum(thresh[y:y+h, x : x+ w])\n        density_e = sums/ ((y+h)* (x+w))\n#         print(f'X: [{x}, {x+w}]_ Y: [{y}, {y+h}] _Density: {density_e}_ Sum = {sums}')\n        if sum_pixel <= sums and density_e >= density_ar :\n#             print(f'id: {i}')\n            idmax = i\n#             sum_pixel= sums\n            density_ar  = density_e\n    return idmax\n\ndef reprocess(image, select = 1):\n    expen = 100\n    \n    if len(image.shape)==3: gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)\n    else : gray = image\n    gray = cv2.GaussianBlur(gray, (7, 7), 0)\n    if select == 1:\n#         print(\"yue\")\n#         level = np.median(gray)\n        level = trimmed_mean(gray.flatten(), 0.2)\n#         print(np.mean(gray))\n        thresh = cv2.threshold(gray, level, 255, cv2.THRESH_BINARY)[1]\n#         thresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 3)\n    else : \n        thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]\n#     min_sum_col = cat_tia(thresh);\n    \n    numLabels, labels, stats, centroids = cv2.connectedComponentsWithStats(\n                    thresh,\n                    4,\n                    cv2.CV_32S\n    )\n\n    idmax = find_id_max(numLabels, labels, stats, centroids, thresh)\n#     idmax = 2\n#     print(idmax)\n    ######## CROP\n    x = stats[idmax, cv2.CC_STAT_LEFT] \n    y = stats[idmax, cv2.CC_STAT_TOP] \n    w = stats[idmax, cv2.CC_STAT_WIDTH] \n    h = stats[idmax, cv2.CC_STAT_HEIGHT] \n#     print(x, y, w, h)\n#     print(\"KICH THUOC : \"+ str(image.shape))\n    w_max =  image.shape[1]\n    h_max =  image.shape[0] - 1\n#     nb_col  = img.shape[1]\n    thresh = thresh/255\n    if (np.sum(thresh[:, 0: int(w_max/2) ]) < np.sum(thresh[:, int(w_max/2)+1 :  ])):\n#         print(\"LEFT\")\n        new_image = image[y: y+h , max(0,x-expen) : ]\n    else :\n        new_image = image[y: y+h , : min(w_max, x + w+ expen)]\n    dim = (512 , 512)\n    new_image = cv2.resize(new_image, dim)\n    return new_image\n\ndef crop_image(image, name_image, id_par):\n    new_image = reprocess(image)\n    file_name = f'/kaggle/working/{id_par}_{name_image}.png';\n    try:\n        cv2.imwrite(file_name, new_image)\n    except:\n#         print(\"EERRRO\")\n        new_image = reprocess(image, select=2)\n\n        try:\n            imageio.imwrite(file_name, new_image)\n        except:\n            print(file_name)\n#             f.write(str(name_image) + 'ngu \\n')\n# cnt = 0\ndef procees(path):\n#     print(path)\n#     global cnt \n#     cnt+= 1\n#     print(cnt)\n    dicom = pydicom.dcmread(path)\n    img = dicom.pixel_array\n    img = apply_windowing(img, dicom)\n    img = (img - img.min()) / (img.max() - img.min())\n\n    if dicom.PhotometricInterpretation == \"MONOCHROME1\":  \n        img = 1 - img\n    image = np.uint8(img * 255)\n    file_name = path.split('/')\n    id_img = file_name[-1].split('.')[0]\n    id_par = file_name[-2].split('.')[0]\n#     file = os.path.splitext(file_name)[0]\n#     print(id_img, id_par)\n    crop_image(image, id_img, id_par)","metadata":{"execution":{"iopub.status.busy":"2023-02-25T08:35:02.679068Z","iopub.execute_input":"2023-02-25T08:35:02.680143Z","iopub.status.idle":"2023-02-25T08:35:02.701383Z","shell.execute_reply.started":"2023-02-25T08:35:02.680099Z","shell.execute_reply":"2023-02-25T08:35:02.700027Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# clean()","metadata":{"execution":{"iopub.status.busy":"2023-02-25T08:35:07.520262Z","iopub.execute_input":"2023-02-25T08:35:07.520725Z","iopub.status.idle":"2023-02-25T08:35:07.525997Z","shell.execute_reply.started":"2023-02-25T08:35:07.520689Z","shell.execute_reply":"2023-02-25T08:35:07.525145Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"### display so sanh \ndef show_images_for_image_ids(image_ids_not,figsize=(48,30),suptitle=None, stt=None):\n\n    fig, axs = plt.subplots(int((len(image_ids_not)+1)/2),4,figsize=figsize)\n    if suptitle: fig.suptitle(f'{suptitle}', fontsize=16)\n    axs = axs.flatten()\n    pos = 0\n    for i in range(len(image_ids_not)):\n        # print(image_ids_not[i])\n#         file_name = os.path.basename(image_ids_not[i])\n#         file = os.path.splitext(file_name)[0]\n#         file_name = image_ids_not[i].split('/')\n#         id_image = os.path.splitext(file_name[-1])[0]\n#         id_parnent = file_name[-2]\n        img = Image.open(image_ids_not[i])\n        axs[pos].imshow(img, cmap=\"bone\")\n        axs[i].set_title(image_ids_not[i].split('_')[-1])\n        pos+=1\n        if pos > len(image_ids_not): break\n#     fig.savefig(f'/kaggle/working/Check_{suptitle}_{stt}.png')\n\n","metadata":{"execution":{"iopub.status.busy":"2023-02-25T08:35:09.402183Z","iopub.execute_input":"2023-02-25T08:35:09.402661Z","iopub.status.idle":"2023-02-25T08:35:09.4111Z","shell.execute_reply.started":"2023-02-25T08:35:09.402622Z","shell.execute_reply":"2023-02-25T08:35:09.409922Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"### display so sanh \ndef show_2image(img1, img2, id_img, figsize=(48,30)):\n\n    fig, axs = plt.subplots(1,2,figsize=figsize)\n                            \n    fig.suptitle(f'{id_img}', fontsize=16)\n    axs = axs.flatten()\n    pos = 0\n   \n#     img1 = Image.open(image_ids_not[i])\n    axs[0].imshow(img1, cmap=\"bone\")\n    axs[1].imshow(img2, cmap=\"bone\")\n    fig.savefig(f'/kaggle/working/Check_{id_img}')\n\n","metadata":{"execution":{"iopub.status.busy":"2023-02-25T08:35:23.934842Z","iopub.execute_input":"2023-02-25T08:35:23.935293Z","iopub.status.idle":"2023-02-25T08:35:23.94405Z","shell.execute_reply.started":"2023-02-25T08:35:23.935244Z","shell.execute_reply":"2023-02-25T08:35:23.941455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# clean()","metadata":{"execution":{"iopub.status.busy":"2023-02-25T08:35:25.12467Z","iopub.execute_input":"2023-02-25T08:35:25.125051Z","iopub.status.idle":"2023-02-25T08:35:25.129844Z","shell.execute_reply.started":"2023-02-25T08:35:25.125021Z","shell.execute_reply":"2023-02-25T08:35:25.128513Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ls_crop = glob.glob('/kaggle/input/test-image-1/*.png')\nfor path in ls_crop:\n#     print(os.path.basename(path))\n    img1 = cv2.imread(path)\n    img2 = cv2.imread(f'/kaggle/input/rsna-breast-cancer-512-pngs/{os.path.basename(path)}')\n    show_2image(img1, img2, os.path.basename(path), figsize=(7,7))\n    ","metadata":{"execution":{"iopub.status.busy":"2023-02-25T08:35:25.944818Z","iopub.execute_input":"2023-02-25T08:35:25.945353Z","iopub.status.idle":"2023-02-25T08:35:53.162976Z","shell.execute_reply.started":"2023-02-25T08:35:25.945305Z","shell.execute_reply":"2023-02-25T08:35:53.161271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ls_path_all = []\n# for i in range (len(data_image)):\n#     path  = f'/kaggle/input/rsna-breast-cancer-detection/train_images/{data_image.patient_id[i]}/{data_image.image_id[i]}.dcm'\n# #     print(path)\n# #     procees(path)\n#     ls_path_all.append(path)","metadata":{"execution":{"iopub.status.busy":"2023-02-25T05:06:20.402464Z","iopub.execute_input":"2023-02-25T05:06:20.402987Z","iopub.status.idle":"2023-02-25T05:06:20.408618Z","shell.execute_reply.started":"2023-02-25T05:06:20.402934Z","shell.execute_reply":"2023-02-25T05:06:20.407056Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# list_not_crop = glob.glob(\"/kaggle/input/test-image-1/*.png\")","metadata":{"execution":{"iopub.status.busy":"2023-02-25T01:50:57.292282Z","iopub.execute_input":"2023-02-25T01:50:57.292683Z","iopub.status.idle":"2023-02-25T01:50:57.314596Z","shell.execute_reply.started":"2023-02-25T01:50:57.292649Z","shell.execute_reply":"2023-02-25T01:50:57.313649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ls_path_all = []\n# for i in range (len(data_image)):\n#     path  = f'/kaggle/input/rsna-breast-cancer-detection/train_images/{data_image.patient_id[i]}/{data_image.image_id[i]}.dcm'\n# #     print(path)\n# #     procees(path)\n#     ls_path_all.append(path)","metadata":{"execution":{"iopub.status.busy":"2023-02-25T01:49:42.177166Z","iopub.execute_input":"2023-02-25T01:49:42.177571Z","iopub.status.idle":"2023-02-25T01:49:42.182586Z","shell.execute_reply.started":"2023-02-25T01:49:42.177541Z","shell.execute_reply":"2023-02-25T01:49:42.181169Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# path  = f'/kaggle/input/rsna-breast-cancer-detection/test-image-1/{data_image.patient_id[i]}/{data_image.image_id[i]}.png'\n# img = cv2.imread(path)\n# plt.imshow(img)","metadata":{"execution":{"iopub.status.busy":"2023-02-25T01:50:06.999853Z","iopub.execute_input":"2023-02-25T01:50:07.000236Z","iopub.status.idle":"2023-02-25T01:50:07.216449Z","shell.execute_reply.started":"2023-02-25T01:50:07.000205Z","shell.execute_reply":"2023-02-25T01:50:07.215011Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# procees('/kaggle/input/rsna-breast-cancer-detection/train_images/10006/1459541791.dcm')","metadata":{"execution":{"iopub.status.busy":"2023-02-24T19:07:17.244796Z","iopub.execute_input":"2023-02-24T19:07:17.24534Z","iopub.status.idle":"2023-02-24T19:07:28.271724Z","shell.execute_reply.started":"2023-02-24T19:07:17.245297Z","shell.execute_reply":"2023-02-24T19:07:28.270302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# def ps(id):\n#     procees(ls_path_all[id])\n# #     print(id)","metadata":{"execution":{"iopub.status.busy":"2023-02-24T19:07:28.274559Z","iopub.execute_input":"2023-02-24T19:07:28.27518Z","iopub.status.idle":"2023-02-24T19:07:28.281981Z","shell.execute_reply.started":"2023-02-24T19:07:28.275124Z","shell.execute_reply":"2023-02-24T19:07:28.280714Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n# def crop_all():\n    \n#     ls = list(range(len(ls_path_all)))\n#     with mp.Pool(2) as p:\n#         p.map(ps,  ls)\n        \n# crop_all()\n","metadata":{"execution":{"iopub.status.busy":"2023-02-24T19:07:28.283705Z","iopub.execute_input":"2023-02-24T19:07:28.284494Z","iopub.status.idle":"2023-02-24T19:07:49.135502Z","shell.execute_reply.started":"2023-02-24T19:07:28.284449Z","shell.execute_reply":"2023-02-24T19:07:49.132857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2023-02-24T17:55:19.52019Z","iopub.execute_input":"2023-02-24T17:55:19.520549Z","iopub.status.idle":"2023-02-24T17:55:51.192425Z","shell.execute_reply.started":"2023-02-24T17:55:19.520519Z","shell.execute_reply":"2023-02-24T17:55:51.191336Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 508520490- \n# 507584895","metadata":{"execution":{"iopub.status.busy":"2023-02-24T17:28:05.578273Z","iopub.execute_input":"2023-02-24T17:28:05.578634Z","iopub.status.idle":"2023-02-24T17:28:05.58722Z","shell.execute_reply.started":"2023-02-24T17:28:05.578598Z","shell.execute_reply":"2023-02-24T17:28:05.585751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# img = cv2.imread('/kaggle/working/40548_1374423447.png')\n# # plt.imshow(img[:, 0: 500])\n# np.sum(img[:, 0: 500])","metadata":{"execution":{"iopub.status.busy":"2023-02-24T17:28:05.588255Z","iopub.status.idle":"2023-02-24T17:28:05.589274Z","shell.execute_reply.started":"2023-02-24T17:28:05.589013Z","shell.execute_reply":"2023-02-24T17:28:05.589039Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# show_img_PNG('/kaggle/working/18674_96888113.png')","metadata":{"execution":{"iopub.status.busy":"2023-02-24T17:18:02.245544Z","iopub.execute_input":"2023-02-24T17:18:02.246549Z","iopub.status.idle":"2023-02-24T17:18:06.142646Z","shell.execute_reply.started":"2023-02-24T17:18:02.246507Z","shell.execute_reply":"2023-02-24T17:18:06.14171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# X: [1932, 3540]_ Y: [0, 3846] _Density: 68.64532708426981\n# crop_images(path, 1932, 0, 3540, 3846)","metadata":{"execution":{"iopub.status.busy":"2023-02-24T16:25:57.857108Z","iopub.execute_input":"2023-02-24T16:25:57.857465Z","iopub.status.idle":"2023-02-24T16:25:59.678808Z","shell.execute_reply.started":"2023-02-24T16:25:57.857434Z","shell.execute_reply":"2023-02-24T16:25:59.677735Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# glob.glob('/kaggle/working/*.png')","metadata":{"execution":{"iopub.status.busy":"2023-02-24T18:07:00.325202Z","iopub.execute_input":"2023-02-24T18:07:00.325614Z","iopub.status.idle":"2023-02-24T18:07:00.3353Z","shell.execute_reply.started":"2023-02-24T18:07:00.325575Z","shell.execute_reply":"2023-02-24T18:07:00.334273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# show_images_for_image_ids(glob.glob('/kaggle/working/*.png'), figsize=(20,50),  suptitle='Image_not_crop', stt=1)","metadata":{"execution":{"iopub.status.busy":"2023-02-24T18:07:01.22063Z","iopub.execute_input":"2023-02-24T18:07:01.221015Z","iopub.status.idle":"2023-02-24T18:07:04.802222Z","shell.execute_reply.started":"2023-02-24T18:07:01.220983Z","shell.execute_reply":"2023-02-24T18:07:04.801068Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\ndef show_img_DICOM(path):\n    dicom = pydicom.dcmread(path)\n    img = dicom.pixel_array\n    img = apply_windowing(img, dicom)\n    img = (img - img.min()) / (img.max() - img.min())\n\n    if dicom.PhotometricInterpretation == \"MONOCHROME1\":  \n        img = 1 - img\n    image = np.uint8(img * 255)\n    plt.imshow( img)\ndef show_img_PNG(path):\n    img = cv2.imread(path)\n    plt.imshow( img)\ndef crop_images(path, x, y, w, h):\n    dicom = pydicom.dcmread(path)\n    img = dicom.pixel_array\n    img = apply_windowing(img, dicom)\n    img = (img - img.min()) / (img.max() - img.min())\n\n    if dicom.PhotometricInterpretation == \"MONOCHROME1\":  \n        img = 1 - img\n    image = np.uint8(img * 255)\n    image = image[y: y+ h, x: x+ w]\n    print(x+w, y+h)\n    plt.imshow( image)\n    ","metadata":{"execution":{"iopub.status.busy":"2023-02-24T15:55:06.853017Z","iopub.execute_input":"2023-02-24T15:55:06.85336Z","iopub.status.idle":"2023-02-24T15:55:06.861887Z","shell.execute_reply.started":"2023-02-24T15:55:06.853331Z","shell.execute_reply":"2023-02-24T15:55:06.860782Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"## Khoi tao bien vu trai va phai\n# L = 0\n## 0 la left\n## 1 la right","metadata":{"execution":{"iopub.status.busy":"2023-02-24T09:35:32.127085Z","iopub.execute_input":"2023-02-24T09:35:32.127478Z","iopub.status.idle":"2023-02-24T09:35:32.13345Z","shell.execute_reply.started":"2023-02-24T09:35:32.127442Z","shell.execute_reply":"2023-02-24T09:35:32.132483Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# def cat_tia_row(img, res):\n#     ## find sum pixel min col\n#     img_ori = res\n# #     img = img/255\n#     nb_row  = img.shape[0]\n#     ls = []\n#     for i in range(nb_row):\n#         x = np.sum(img[i, :])\n#         ls.append(x)\n#     ## xet left right\n#     vl = 5\n#     y1 = nb_row\n#     y2 = 0\n#     for i in range(int(nb_row/2), nb_row):\n#         if ls[i] <= vl:\n#             y1 = i\n#             break\n#     for i in reversed(range(int(nb_row/2))):\n#         if ls[i] <= vl:\n#             y2 = i\n#             break\n#     return img_ori[y2: y1, :]","metadata":{"execution":{"iopub.status.busy":"2023-02-24T09:35:32.135324Z","iopub.execute_input":"2023-02-24T09:35:32.135793Z","iopub.status.idle":"2023-02-24T09:35:32.145293Z","shell.execute_reply.started":"2023-02-24T09:35:32.135757Z","shell.execute_reply":"2023-02-24T09:35:32.144214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# def cat_tia_col(img, res):\n#     ## find sum pixel min col\n#     img_ori = res\n# #     img = img/255\n#     vl = np.sum(img[:, 0])\n#     nb_col  = img.shape[1]\n#     ls = []\n#     for i in range(nb_col):\n#         x = np.sum(img[:, i])\n#         vl = min(vl, x)\n#         ls.append(x)\n# #     print(ls)\n#     if vl > img.shape[0]/3: \n# #         print(\"No crop col\")\n#         return img_ori\n#     ## xet left right\n\n#     ## vì sẽ có các giá trị tương tự nhau nên ta sẽ cộn một lượng phụ trợ vào vl\n#     vl += 10\n#     if (np.sum(img[:, 0: int(nb_col/2) ]) > np.sum(img[:, int(nb_col/2)+1 :  ])):\n#         L = 0\n#         for i in range(nb_col):\n#             if ls[i] <= vl:\n# #                 print(f'Col = {i}, vl = {ls[i]}')\n#                 img_ori = img_ori[:, : i + 50]\n#                 return img_ori\n#     else :\n#         L = 1\n#         for i in reversed(range(nb_col)):\n#             if ls[i] <= vl:\n# #                 print(f'Col = {i}, vl = {ls[i]}')\n#                 img_ori = img_ori[:, i-50: ]\n#                 return img_ori\n                \n#     return img_ori                                 \n        ","metadata":{"execution":{"iopub.status.busy":"2023-02-24T09:35:32.147064Z","iopub.execute_input":"2023-02-24T09:35:32.147491Z","iopub.status.idle":"2023-02-24T09:35:32.160184Z","shell.execute_reply.started":"2023-02-24T09:35:32.147455Z","shell.execute_reply":"2023-02-24T09:35:32.159151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ## show hist \n# def process_crop(img):\n#     if len(img.shape) == 3: gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)\n#     else: gray = img\n#     gray =  cv2.GaussianBlur(gray, (7, 7), 0)\n#     # img = cv2.threshold(img, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]\n#     image_gray = cv2.threshold(gray, 30, 255, cv2.THRESH_BINARY)[1]\n#     imgcp = image_gray/255\n#     h, w = image_gray.shape\n#     if((h*w)-10 <= np.sum(imgcp)):\n\n#         image_gray = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]\n    \n#     if((h*w)/2 >= np.sum(imgcp)):\n#         img = cat_tia_col(imgcp, img)\n# #         print(img)\n#         img = cat_tia_row(imgcp, img)\n#     return img","metadata":{"execution":{"iopub.status.busy":"2023-02-24T09:35:32.163385Z","iopub.execute_input":"2023-02-24T09:35:32.163983Z","iopub.status.idle":"2023-02-24T09:35:32.17257Z","shell.execute_reply.started":"2023-02-24T09:35:32.163955Z","shell.execute_reply":"2023-02-24T09:35:32.171553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import imageio\n\n# def procees_dicom(path):\n    \n# #     print(path.split('/'))\n#     dicom = pydicom.dcmread(path)\n#     img = dicom.pixel_array\n#     img = apply_windowing(img, dicom)\n#     img = (img - img.min()) / (img.max() - img.min())\n#     if dicom.PhotometricInterpretation == \"MONOCHROME1\":  \n#         img = 1 - img\n#     image = np.uint8(img * 255)\n# #     image = cv2.imread(path)\n#     ### Get name\n#     file_name = path.split('/')\n#     id_image = os.path.splitext(file_name[-1])[0]\n#     id_parnent = file_name[-2]\n# #     print(id_image, id_parnent)\n#     img = process_crop(image)\n#     dim = (512, 512)\n#     img_resized = cv2.resize(img, dim)\n#     imageio.imwrite(f'{id_parnent}_{id_image}.png',  img_resized)\n# #     imageio.imwrite('image_writing.png', img_resized)","metadata":{"execution":{"iopub.status.busy":"2023-02-24T09:37:04.386224Z","iopub.execute_input":"2023-02-24T09:37:04.386949Z","iopub.status.idle":"2023-02-24T09:37:04.395321Z","shell.execute_reply.started":"2023-02-24T09:37:04.386913Z","shell.execute_reply":"2023-02-24T09:37:04.393823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# clean()","metadata":{"execution":{"iopub.status.busy":"2023-02-24T09:37:41.643978Z","iopub.execute_input":"2023-02-24T09:37:41.644349Z","iopub.status.idle":"2023-02-24T09:37:41.6709Z","shell.execute_reply.started":"2023-02-24T09:37:41.644305Z","shell.execute_reply":"2023-02-24T09:37:41.669402Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# time.\n# procees_dicom('/kaggle/input/rsna-breast-cancer-detection/train_images/2810/25325183.dcm')","metadata":{"execution":{"iopub.status.busy":"2023-02-24T09:37:10.23685Z","iopub.execute_input":"2023-02-24T09:37:10.237219Z","iopub.status.idle":"2023-02-24T09:37:11.317366Z","shell.execute_reply.started":"2023-02-24T09:37:10.237187Z","shell.execute_reply":"2023-02-24T09:37:11.316385Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# len(glob.glob('/kaggle/input/test-image-1/*.png'))","metadata":{"execution":{"iopub.status.busy":"2023-02-24T08:00:01.590503Z","iopub.execute_input":"2023-02-24T08:00:01.590856Z","iopub.status.idle":"2023-02-24T08:00:02.379284Z","shell.execute_reply.started":"2023-02-24T08:00:01.590826Z","shell.execute_reply":"2023-02-24T08:00:02.378141Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Kiểm tra các tấm ảnh còn thiếu","metadata":{}},{"cell_type":"code","source":"ws = glob.glob('/kaggle/input/test-image-1/*.png')\nos.path.basename(ws[1])\nimage_final = [os.path.basename(ws[i]) for i in range(len(ws))]\nimage_not_crop = []\n","metadata":{"execution":{"iopub.status.busy":"2023-02-25T01:52:01.440747Z","iopub.execute_input":"2023-02-25T01:52:01.441196Z","iopub.status.idle":"2023-02-25T01:52:01.468735Z","shell.execute_reply.started":"2023-02-25T01:52:01.441159Z","shell.execute_reply":"2023-02-25T01:52:01.467742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(image_final)","metadata":{"execution":{"iopub.status.busy":"2023-02-25T01:52:11.699902Z","iopub.execute_input":"2023-02-25T01:52:11.700264Z","iopub.status.idle":"2023-02-25T01:52:11.706476Z","shell.execute_reply.started":"2023-02-25T01:52:11.700234Z","shell.execute_reply":"2023-02-25T01:52:11.705467Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(len(data_image)):\n    path = f'{data_image.patient_id[i]}_{data_image.image_id[i]}.png'\n    if path not in image_final:\n#         print(1)\n        image_not_crop.append(f'{data_image.patient_id[i]}/{data_image.image_id[i]}.dcm')\n#     print(path)","metadata":{"execution":{"iopub.status.busy":"2023-02-25T01:52:30.444874Z","iopub.execute_input":"2023-02-25T01:52:30.445267Z","iopub.status.idle":"2023-02-25T01:52:38.831486Z","shell.execute_reply.started":"2023-02-25T01:52:30.445232Z","shell.execute_reply":"2023-02-25T01:52:38.830283Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(image_not_crop)","metadata":{"execution":{"iopub.status.busy":"2023-02-25T01:55:10.89869Z","iopub.execute_input":"2023-02-25T01:55:10.899775Z","iopub.status.idle":"2023-02-25T01:55:10.905037Z","shell.execute_reply.started":"2023-02-25T01:55:10.89974Z","shell.execute_reply":"2023-02-25T01:55:10.904358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def ps(id):\n    procees(f'/kaggle/input/rsna-breast-cancer-detection/train_images/{image_not_crop[id]}')\n#     print(id)","metadata":{"execution":{"iopub.status.busy":"2023-02-25T01:57:02.070207Z","iopub.execute_input":"2023-02-25T01:57:02.070581Z","iopub.status.idle":"2023-02-25T01:57:02.075203Z","shell.execute_reply.started":"2023-02-25T01:57:02.070547Z","shell.execute_reply":"2023-02-25T01:57:02.074315Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# image_not_crop[1]\n# /kaggle/input/rsna-breast-cancer-detection/test_images","metadata":{"execution":{"iopub.status.busy":"2023-02-25T01:55:42.898068Z","iopub.execute_input":"2023-02-25T01:55:42.898505Z","iopub.status.idle":"2023-02-25T01:55:42.907439Z","shell.execute_reply.started":"2023-02-25T01:55:42.898471Z","shell.execute_reply":"2023-02-25T01:55:42.906197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n# def crop_all():\n    \n#     ls = list(range(len(image_not_crop)))\n#     with mp.Pool(2) as p:\n#         p.map(ps,  ls)\n        \n# crop_all()\n","metadata":{"execution":{"iopub.status.busy":"2023-02-25T01:57:04.242998Z","iopub.execute_input":"2023-02-25T01:57:04.243351Z","iopub.status.idle":"2023-02-25T01:57:34.149733Z","shell.execute_reply.started":"2023-02-25T01:57:04.243322Z","shell.execute_reply":"2023-02-25T01:57:34.148486Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# ----------------------------------------------------------------------------------------------------------------------------","metadata":{}},{"cell_type":"code","source":"# link_path = []\n# for i in range(len(image_not_crop)):\n#     path = f'/kaggle/input/rsna-breast-cancer-detection/train_images/{image_not_crop[i]}'\n#     link_path.append(path)","metadata":{"execution":{"iopub.status.busy":"2023-02-24T09:50:00.4881Z","iopub.execute_input":"2023-02-24T09:50:00.48846Z","iopub.status.idle":"2023-02-24T09:50:00.499967Z","shell.execute_reply.started":"2023-02-24T09:50:00.488427Z","shell.execute_reply":"2023-02-24T09:50:00.49881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# link_path[1]","metadata":{"execution":{"iopub.status.busy":"2023-02-24T09:50:00.502482Z","iopub.execute_input":"2023-02-24T09:50:00.502967Z","iopub.status.idle":"2023-02-24T09:50:00.51272Z","shell.execute_reply.started":"2023-02-24T09:50:00.502934Z","shell.execute_reply":"2023-02-24T09:50:00.510893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import shutil\ndef clean():\n    shutil.rmtree(\"/kaggle/working/\")","metadata":{"execution":{"iopub.status.busy":"2023-02-25T05:22:57.393472Z","iopub.execute_input":"2023-02-25T05:22:57.393865Z","iopub.status.idle":"2023-02-25T05:22:57.399162Z","shell.execute_reply.started":"2023-02-25T05:22:57.393834Z","shell.execute_reply":"2023-02-25T05:22:57.398072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# link_path = []\n# for i in range(len(data_image)):\n#     path = f'/kaggle/input/rsna-breast-cancer-detection/train_images/{data_image.patient_id[i]}/{data_image.image_id[i]}.dcm'\n#     link_path.append(path)","metadata":{"execution":{"iopub.status.busy":"2023-02-24T09:50:00.523263Z","iopub.execute_input":"2023-02-24T09:50:00.523633Z","iopub.status.idle":"2023-02-24T09:50:00.534267Z","shell.execute_reply.started":"2023-02-24T09:50:00.5236Z","shell.execute_reply":"2023-02-24T09:50:00.533295Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import time\n# start = time.time()\n\n# def crop_all():\n    \n#     ls = link_path\n#     with mp.Pool(2) as p:\n#         p.map(procees_dicom,  ls)\n# crop_all()\n\n# end = time.time()\n# print(end - start)","metadata":{"execution":{"iopub.status.busy":"2023-02-24T09:50:47.04058Z","iopub.execute_input":"2023-02-24T09:50:47.040972Z","iopub.status.idle":"2023-02-24T09:51:00.88057Z","shell.execute_reply.started":"2023-02-24T09:50:47.04094Z","shell.execute_reply":"2023-02-24T09:51:00.878998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# crop_all()","metadata":{"execution":{"iopub.status.busy":"2023-02-17T14:17:40.244381Z","iopub.execute_input":"2023-02-17T14:17:40.244751Z","iopub.status.idle":"2023-02-17T14:19:13.939595Z","shell.execute_reply.started":"2023-02-17T14:17:40.244713Z","shell.execute_reply":"2023-02-17T14:19:13.938238Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# /kaggle/input/rsna-breast-cancer-detection/train_images/10006/1459541791.dcm","metadata":{"execution":{"iopub.status.busy":"2023-02-17T14:19:13.942436Z","iopub.execute_input":"2023-02-17T14:19:13.942852Z","iopub.status.idle":"2023-02-17T14:21:09.973597Z","shell.execute_reply.started":"2023-02-17T14:19:13.942811Z","shell.execute_reply":"2023-02-17T14:21:09.972172Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# glob.glob('/kaggle/input/rsna-breast-cancer-detection/train_images/45248/*.dcm')","metadata":{"execution":{"iopub.status.busy":"2023-02-24T09:49:15.237009Z","iopub.execute_input":"2023-02-24T09:49:15.23745Z","iopub.status.idle":"2023-02-24T09:49:15.24968Z","shell.execute_reply.started":"2023-02-24T09:49:15.23741Z","shell.execute_reply":"2023-02-24T09:49:15.248519Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# check[1]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# show_images_for_image_ids(check, figsize=(20,50),  suptitle='Image_not_crop', stt=1)","metadata":{"execution":{"iopub.status.busy":"2023-02-17T13:37:05.553532Z","iopub.execute_input":"2023-02-17T13:37:05.553987Z","iopub.status.idle":"2023-02-17T13:37:19.927222Z","shell.execute_reply.started":"2023-02-17T13:37:05.553951Z","shell.execute_reply":"2023-02-17T13:37:19.925968Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# show_images_for_image_ids(check2, figsize=(20,50),  suptitle='Image_not_crop', stt=2)\n# show_images_for_image_ids(check3, figsize=(20,50),  suptitle='Image_not_crop', stt=3)\n# show_images_for_image_ids(check4, figsize=(20,50),  suptitle='Image_not_crop', stt=4)","metadata":{"execution":{"iopub.status.busy":"2023-02-17T14:22:53.789533Z","iopub.execute_input":"2023-02-17T14:22:53.790308Z","iopub.status.idle":"2023-02-17T14:23:38.289406Z","shell.execute_reply.started":"2023-02-17T14:22:53.790264Z","shell.execute_reply":"2023-02-17T14:23:38.288291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# img = process('/kaggle/working/361203119.png')\n# plt.imshow(img):","metadata":{"execution":{"iopub.status.busy":"2023-02-17T14:15:08.055755Z","iopub.execute_input":"2023-02-17T14:15:08.056107Z","iopub.status.idle":"2023-02-17T14:15:08.06317Z","shell.execute_reply.started":"2023-02-17T14:15:08.056078Z","shell.execute_reply":"2023-02-17T14:15:08.061712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # download hình anh\n# import os\n# os.chdir(r'/kaggle/working/')\n# from IPython.display import FileLink\n# !zip -r file.zip '/kaggle/working/'\n# FileLink(r'file.zip')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import shutil\n# shutil.rmtree(\"/kaggle/working/\")","metadata":{"execution":{"iopub.status.busy":"2023-02-24T14:11:01.364387Z","iopub.execute_input":"2023-02-24T14:11:01.364756Z","iopub.status.idle":"2023-02-24T14:11:01.385399Z","shell.execute_reply.started":"2023-02-24T14:11:01.364704Z","shell.execute_reply":"2023-02-24T14:11:01.383983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# img  = cv2.imread('/kaggle/working/96888113.png')\n\n# #     if len(img.shape) == 3: \n\n# gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)\n# #     else: gray = img\n# gray =  cv2.GaussianBlur(gray, (7, 7), 0)\n# # image_gray = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]\n# image_gray = cv2.threshold(gray, 30, 255, cv2.THRESH_BINARY)[1]\n# imgcp = image_gray/255 \n# ls1 = []\n# for i in range(imgcp.shape[1]):\n#     x = np.sum(imgcp[:, i])\n#     ls1.append(x)\n# ls2 = []\n# for i in range(imgcp.shape[0]):\n#     x = np.sum(imgcp[i, :])\n#     ls2.append(x)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import seaborn as sns\n# import pandas as pd\n# import matplotlib.pyplot as plt\n\n# fig, axes = plt.subplots(1, 2, sharex=True, figsize=(10,5))\n# sns.barplot(ax=axes[0], x=list(range(0, 512)), y= ls1)\n# sns.barplot(ax=axes[1],x=list(range(0, 512)), y= ls2) \n# fig.show()\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import seaborn as sns \n# import pandas as pd\n\n# sns.barplot(x=list(range(0, 512)), y= ls1)# sns.lineplot(data=fifa_data)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# def show_img_hist():\n#     img  = cv2.imread('/kaggle/working/96888113.png')\n\n# #     if len(img.shape) == 3: \n        \n#     gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)\n# #     else: gray = img\n#     gray =  cv2.GaussianBlur(gray, (7, 7), 0)\n#     # image_gray = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]\n#     image_gray = cv2.threshold(gray, 30, 255, cv2.THRESH_BINARY)[1]\n#     imgcp = image_gray/255 \n#     ls1 = []\n#     for i in range(imgcp.shape[1]):a\n#         x = np.sum(imgcp[:, i])\n#         ls1.append(x)\n#     ls2 = []\n#     for i in range(imgcp.shape[0]):\n#         x = np.sum(imgcp[i, :])\n#         ls2.append(x)\n#     fig, axes = plt.subplots(1, 2, sharex=True, figsize=(10,5))\n# #     sns.barplot(ax=axes[0], x=list(range(0, 512)), y= ls1)\n# #     sns.barplot(ax=axes[1],x=list(range(0, 512)), y= ls2) \n#     fig.show()\n# show_img_hist()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2023-02-24T08:58:51.975016Z","iopub.execute_input":"2023-02-24T08:58:51.975395Z","iopub.status.idle":"2023-02-24T08:58:52.255303Z","shell.execute_reply.started":"2023-02-24T08:58:51.975359Z","shell.execute_reply":"2023-02-24T08:58:52.254344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# img  = cv2.imread('/kaggle/input/rsna-breast-cancer-512-pngs/40317_840036202.png')\n\n# #     if len(img.shape) == 3: \n        \n# gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)\n# #     else: gray = img\n# gray =  cv2.GaussianBlur(gray, (7, 7), 0)\n# # image_gray = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]\n# image_gray = cv2.threshold(gray, 30, 255, cv2.THRESH_BINARY)[1]\n# imgcp = image_gray/255 \n# ls1 = []\n# for i in range(imgcp.shape[1]):\n#     x = np.sum(imgcp[:, i])\n#     ls1.append(x)\n# ls2 = []\n# for i in range(imgcp.shape[0]):\n#     x = np.sum(imgcp[i, :])\n#     ls2.append(x)\n# fig, axes = plt.subplots(1, 2, sharex=True, figsize=(10,5))\n# sns.barplot(ax=axes[0], x=list(range(0, 512)), y= ls1)\n# sns.barplot(ax=axes[1],x=list(range(0, 512)), y= ls2) \n# fig.show()","metadata":{"execution":{"iopub.status.busy":"2023-02-24T09:05:59.607244Z","iopub.execute_input":"2023-02-24T09:05:59.607848Z","iopub.status.idle":"2023-02-24T09:06:12.698528Z","shell.execute_reply.started":"2023-02-24T09:05:59.607813Z","shell.execute_reply":"2023-02-24T09:06:12.697556Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ls = []\n# for i in range(imgcp.shape[0]):\n#     x = np.sum(imgcp[i, :])\n#     ls.append(x)\n# import seaborn as sns \n# import pandas as pd\n\n# sns.barplot(x=list(range(0, 512)), y= ls)# sns.lineplot(data=fifa_data)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# img = Image.open('/kaggle/input/test-image-1/10006_1459541791.png')","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}