{"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":"import numpy as np\nimport cv2 as cv\nimport matplotlib.pyplot as plt\nfrom tqdm import tqdm\ndef error_diffusion(image,filtre,size):\n  x=np.ones((image.shape[0]+2*size,image.shape[1]+2*size))*127\n  x[size:-size,size:-size]=image\n  y=x.copy()\n  for i in range(size,x.shape[0]-size):\n    for j in range(size,x.shape[1]-size):\n      if x[i,j]>127:\n          y[i,j]=255\n      else:\n          y[i,j]=0\n      error=int(-y[i][j]+x[i][j])\n      for (dx,dy,val) in filtre:\n        x[i+dx][j+dy]+=int(error*val)\n        \n\n  return y[size:-size,size:-size]","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-10-21T19:13:29.059873Z","iopub.execute_input":"2022-10-21T19:13:29.060259Z","iopub.status.idle":"2022-10-21T19:13:29.06946Z","shell.execute_reply.started":"2022-10-21T19:13:29.060228Z","shell.execute_reply":"2022-10-21T19:13:29.068357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"jarvis=[\n       (0, 1, 7 / 48),\n        (0, 2, 5 / 48),\n        (1, -2, 3 / 48),\n        (1, -1, 5 / 48),\n        (1, 0, 7 / 48),\n        (1, 1, 5 / 48),\n        (1, 2, 3 / 48),\n        (2, -2, 1 / 48),\n        (2, -1, 3 / 48),\n        (2, 0, 5 / 48),\n        (2, 1, 3 / 48),\n        (2, 2, 1 / 48),\n]","metadata":{"execution":{"iopub.status.busy":"2022-10-21T19:13:33.347959Z","iopub.execute_input":"2022-10-21T19:13:33.348396Z","iopub.status.idle":"2022-10-21T19:13:33.35865Z","shell.execute_reply.started":"2022-10-21T19:13:33.348357Z","shell.execute_reply":"2022-10-21T19:13:33.357436Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tqdm import tqdm\nimport os\nfor dirs in os.listdir(\"../input/imagenet-object-localization-challenge/ILSVRC/Data/CLS-LOC/train\")[30:]:\n    os.mkdir(dirs)\n    images =os.listdir(\"../input/imagenet-object-localization-challenge/ILSVRC/Data/CLS-LOC/train/\"+dirs)\n    for img in tqdm(images):\n        rose=cv.imread(\"../input/imagenet-object-localization-challenge/ILSVRC/Data/CLS-LOC/train/\"+dirs+\"/\"+img,0)\n        cv.imwrite(dirs+'/'+img,error_diffusion(rose,jarvis,2))","metadata":{"execution":{"iopub.status.busy":"2022-10-21T19:13:37.503242Z","iopub.execute_input":"2022-10-21T19:13:37.503609Z","iopub.status.idle":"2022-10-21T19:14:48.240015Z","shell.execute_reply.started":"2022-10-21T19:13:37.503579Z","shell.execute_reply":"2022-10-21T19:14:48.238632Z"},"trusted":true},"execution_count":null,"outputs":[]}]}