{"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 dicomsdl\n!cp /kaggle/input/nvjpeg2k/nvjpeg2k.so ./","metadata":{"execution":{"iopub.status.busy":"2022-12-26T08:26:41.295804Z","iopub.execute_input":"2022-12-26T08:26:41.296248Z","iopub.status.idle":"2022-12-26T08:26:54.203971Z","shell.execute_reply.started":"2022-12-26T08:26:41.296162Z","shell.execute_reply":"2022-12-26T08:26:54.202678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import dicomsdl as dicom, os, pandas as pd, time, joblib, nvjpeg2k, pydicom\nst = time.time()\nprint(\"start\")\nlenv = 32000\nnv2000 = '1.2.840.10008.1.2.4.90'\nlossless = '1.2.840.10008.1.2.4.70'\ndf = pd.read_csv(\"/kaggle/input/rsna-breast-cancer-detection/train.csv\")\ncount = int(lenv/2)\n\ndef rtf(r):\n    return f\"/kaggle/input/rsna-breast-cancer-detection/train_images/{r['patient_id']}/{r['image_id']}.dcm\"\n    \ndef process_nv2000(count):\n    decoder = nvjpeg2k.Decoder()\n    tsize, c = 0,0\n    st = time.time()\n    for i,r in df.iterrows():\n        f = rtf(r)\n        dcmfile = pydicom.dcmread(f)\n        if dcmfile.file_meta.TransferSyntaxUID == nv2000:\n            offset = dcmfile.PixelData.find(b\"\\x00\\x00\\x00\\x0C\")\n            hackedbitstream = bytearray()\n            hackedbitstream.extend(dcmfile.PixelData[offset:])\n            d = decoder.decode(hackedbitstream)\n            tsize = tsize + d.nbytes\n            c = c + 1\n            if c > count:\n                return tsize, time.time() - st\n            \ndef process_lossless(count):\n    tsize, c = 0,0\n    st = time.time()\n    for i,r in df.iterrows():\n        f = rtf(r)\n        dcmfile = pydicom.dcmread(f)\n        if dcmfile.file_meta.TransferSyntaxUID == lossless:\n            d = dicom.open(f).pixelData()\n            tsize = tsize + d.nbytes\n            c = c + 1\n            if c > count:\n                return tsize, time.time() - st\n            \nt2000,tlossless = 0,0\njobs = [(process_nv2000, count), (process_lossless, int(count/2)),\n    (process_lossless, int(count/2))] \nres = None\nwith joblib.Parallel(n_jobs=2) as parallel:\n    res = parallel(joblib.delayed(x[0])(x[1]) for x in jobs)\n    \nprint(res)\n#print(t2s, tls, tls2,(t2s+tls+tls2)/(lenv*1000000), t2t, tlt, tlt2)\n\nprint((time.time() - st)/lenv)\n#0.13869014978408814","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-12-26T08:57:49.823257Z","iopub.execute_input":"2022-12-26T08:57:49.823669Z","iopub.status.idle":"2022-12-26T08:58:09.855587Z","shell.execute_reply.started":"2022-12-26T08:57:49.823634Z","shell.execute_reply":"2022-12-26T08:58:09.854517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}