{"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":"\n","metadata":{}},{"cell_type":"markdown","source":"# Dataset for the Background Class","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport os\nimport cv2\nimport shutil\nfrom PIL import Image,ImageOps \nimport matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2022-12-11T04:10:15.844132Z","iopub.execute_input":"2022-12-11T04:10:15.844605Z","iopub.status.idle":"2022-12-11T04:10:15.851511Z","shell.execute_reply.started":"2022-12-11T04:10:15.844570Z","shell.execute_reply":"2022-12-11T04:10:15.850051Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Monochromatic background.","metadata":{}},{"cell_type":"code","source":"folderlocation = './data/'\nif not os.path.exists(folderlocation):\n    os.mkdir(folderlocation)\nfolderlocation = './data/Monochrome/'\nif not os.path.exists(folderlocation):\n    os.mkdir(folderlocation)\n\nimage_iter = np.zeros([50, 50, 3])\n\nfor iter1 in range(6):\n    for iter2 in range(6):\n        for iter3 in range(6):\n            image_iter[:,:,0] = iter1*50\n            image_iter[:,:,1] = iter2*50\n            image_iter[:,:,2] = iter3*50\n            \n            cv2.imwrite(folderlocation + \"Monochrome_\"+str(iter1)+str(iter2)+str(iter3)+\".png\", image_iter)\n            ","metadata":{"execution":{"iopub.status.busy":"2022-12-11T04:10:15.858144Z","iopub.execute_input":"2022-12-11T04:10:15.858846Z","iopub.status.idle":"2022-12-11T04:10:15.889537Z","shell.execute_reply.started":"2022-12-11T04:10:15.858786Z","shell.execute_reply":"2022-12-11T04:10:15.888305Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## intel image classification training set\n\n#### Images without human and animal: \nForest 1st 30 image, \nGlacier [0] to [5] and [28] to [58] \nMountain [0] to [60], except [4]\nSea [0] to [21]\nBuildings [0] to [59], except [14] \n\n#### Images without animal: \nStreet 1st 60\n#### Images without car as a major object: \nStreet 1st 60 except [28]","metadata":{}},{"cell_type":"code","source":"folderlocation = './data/'\nif not os.path.exists(folderlocation):\n    os.mkdir(folderlocation)\nfolderlocation = './data/Intel/'\nif not os.path.exists(folderlocation):\n    os.mkdir(folderlocation)\n\n    \nPATH = '/kaggle/input/intel-image-classification/seg_train/seg_train/forest/'\nfilenames = next(os.walk(PATH), (None, None, []))[2] \nfilenames = sorted(filenames)\nprint(filenames[0])\n# Show the image\nimage = Image.open(PATH + filenames[0]) \n#plt.figure(figsize=(15, 10))\nplt.imshow(image)\nplt.axis('off')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-11T04:10:15.891514Z","iopub.execute_input":"2022-12-11T04:10:15.891854Z","iopub.status.idle":"2022-12-11T04:10:17.579261Z","shell.execute_reply.started":"2022-12-11T04:10:15.891824Z","shell.execute_reply":"2022-12-11T04:10:17.578157Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Also adding inverted omage\ninverted_image = ImageOps.invert(image)\n\nplt.imshow(inverted_image)\nplt.axis('off')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-11T04:10:17.580733Z","iopub.execute_input":"2022-12-11T04:10:17.581096Z","iopub.status.idle":"2022-12-11T04:10:17.729405Z","shell.execute_reply.started":"2022-12-11T04:10:17.581063Z","shell.execute_reply":"2022-12-11T04:10:17.728036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Forest Class\nfor iter1 in range(90):\n    shutil.copyfile(PATH + filenames[iter1], folderlocation +filenames[iter1])\n    \n\nPATH = '/kaggle/input/intel-image-classification/seg_train/seg_train/glacier/'\nfilenames = next(os.walk(PATH), (None, None, []))[2]  \nfilenames = sorted(filenames)\n\n# glacier class\nfor iter1 in range(28,58):\n    shutil.copyfile(PATH + filenames[iter1], folderlocation +filenames[iter1])\n    \nPATH = '/kaggle/input/intel-image-classification/seg_train/seg_train/mountain/'\nfilenames = next(os.walk(PATH), (None, None, []))[2]  \nfilenames = sorted(filenames)\n\n# mountain class\nfor iter1 in range(10,40):\n    shutil.copyfile(PATH + filenames[iter1], folderlocation +filenames[iter1])\n    \nPATH = '/kaggle/input/intel-image-classification/seg_train/seg_train/sea/'\nfilenames = next(os.walk(PATH), (None, None, []))[2]  \nfilenames = sorted(filenames)\n\n# sea class\nfor iter1 in range(20):\n    shutil.copyfile(PATH + filenames[iter1], folderlocation +filenames[iter1])\n    \nPATH = '/kaggle/input/intel-image-classification/seg_train/seg_train/buildings/'\nfilenames = next(os.walk(PATH), (None, None, []))[2]  \nfilenames = sorted(filenames)\n\n# buildings class\nfor iter1 in range(10,60):\n    if filenames[iter1] == '1045.jpg':\n        print('1045.jpg'+ ' contains a car image')\n        continue\n    shutil.copyfile(PATH + filenames[iter1], folderlocation +filenames[iter1])\n    \nfolderlocation = './data/IntelStreet/'\nif not os.path.exists(folderlocation):\n    os.mkdir(folderlocation)\n    \nPATH = '/kaggle/input/intel-image-classification/seg_train/seg_train/street/'\nfilenames = next(os.walk(PATH), (None, None, []))[2]  \nfilenames = sorted(filenames)\n\n# street class\nfor iter1 in range(30,60):\n    shutil.copyfile(PATH + filenames[iter1], folderlocation +filenames[iter1])\n    ","metadata":{"execution":{"iopub.status.busy":"2022-12-11T04:10:17.731141Z","iopub.execute_input":"2022-12-11T04:10:17.732044Z","iopub.status.idle":"2022-12-11T04:10:25.328148Z","shell.execute_reply.started":"2022-12-11T04:10:17.731985Z","shell.execute_reply":"2022-12-11T04:10:25.327131Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## GrassClover Dataset training set\nGrass. Often pictures contain small flower, high resolution, 261 images in training set. Images\n[0,1,3,4,9,19,26,29] have no flower.","metadata":{}},{"cell_type":"code","source":"folderlocation = './data/Grass/'\nif not os.path.exists(folderlocation):\n    os.mkdir(folderlocation)\n\nPATH = '/kaggle/input/grassclover-dataset/biomass_data/train/images/'\nfilenames = next(os.walk(PATH), (None, None, []))[2]  \nfilenames = sorted(filenames)\n\nimg = cv2.imread(PATH + filenames[1], cv2.IMREAD_UNCHANGED)\nprint('Example Image size: ',img.shape)\n\nplt.imshow(img)\nplt.axis('off')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-11T04:10:25.330892Z","iopub.execute_input":"2022-12-11T04:10:25.331491Z","iopub.status.idle":"2022-12-11T04:10:26.624264Z","shell.execute_reply.started":"2022-12-11T04:10:25.331456Z","shell.execute_reply":"2022-12-11T04:10:26.623049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def inverte(imagem, name):\n    imagem = (255-imagem)\n    cv2.imwrite(name, imagem)\n\ndim = (512, 512)\nfor iter1 in [0,1,3,4,9,19,26,29]:  \n    img_count =0\n    img = cv2.imread(PATH + filenames[iter1], cv2.IMREAD_UNCHANGED)\n    \n    # Resize and save\n    resized = cv2.resize(img, dim, interpolation = cv2.INTER_AREA)\n    cv2.imwrite(folderlocation + str(img_count) +'_'+filenames[iter1], resized)\n    inverte(resized,folderlocation + str(img_count) +'_i_'+filenames[iter1])\n    img_count = img_count + 1\n    \n    # Crop and save\n    for iter2 in [100,500,900,1300,1700]:\n        for iter3 in [100,500,900,1300,1700]:\n            resized = img[iter2:dim[0]+iter2,iter3:dim[0]+iter3,:]\n            cv2.imwrite(folderlocation + str(img_count) +'_'+filenames[iter1], resized)\n            inverte(resized,folderlocation + str(img_count) +'_i_'+filenames[iter1])\n            img_count = img_count + 1","metadata":{"execution":{"iopub.status.busy":"2022-12-11T04:10:26.625663Z","iopub.execute_input":"2022-12-11T04:10:26.626208Z","iopub.status.idle":"2022-12-11T04:10:30.964068Z","shell.execute_reply.started":"2022-12-11T04:10:26.626175Z","shell.execute_reply":"2022-12-11T04:10:30.962737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Understanding Clouds from Satellite Images Dataset training set\nAll images are human, animal, flower free","metadata":{}},{"cell_type":"code","source":"folderlocation = './data/space/'\nif not os.path.exists(folderlocation):\n    os.mkdir(folderlocation)\n\nPATH = '/kaggle/input/understanding_cloud_organization/train_images/'\nfilenames = next(os.walk(PATH), (None, None, []))[2]  \nfilenames = sorted(filenames)\n\nimg = cv2.imread(PATH + filenames[1], cv2.IMREAD_UNCHANGED)\nprint('Example Image size: ',img.shape)\n\nplt.imshow(img)\nplt.axis('off')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-11T04:10:30.965339Z","iopub.execute_input":"2022-12-11T04:10:30.965667Z","iopub.status.idle":"2022-12-11T04:10:35.445202Z","shell.execute_reply.started":"2022-12-11T04:10:30.965637Z","shell.execute_reply":"2022-12-11T04:10:35.444032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dim2 = (200, 200)\nfor iter1 in range(10):  \n    img_count =0\n    img = cv2.imread(PATH + filenames[iter1], cv2.IMREAD_UNCHANGED)\n    \n    # Resize and save\n    resized = cv2.resize(img, dim, interpolation = cv2.INTER_AREA)\n    cv2.imwrite(folderlocation + str(img_count) +'_' +filenames[iter1], resized)\n    inverte(resized,folderlocation + str(img_count) +'_i_'+filenames[iter1])\n    img_count = img_count + 1\n    \n    # Crop and save\n    for iter2 in [100,700]:\n        for iter3 in [100,700]:\n            resized = img[iter2:dim[0]+iter2,iter3:dim[0]+iter3,:]\n            cv2.imwrite(folderlocation + str(img_count) +'_'+filenames[iter1], resized)\n            inverte(resized,folderlocation + str(img_count) +'_i_'+filenames[iter1])\n            img_count = img_count + 1\n            \n    # Smaller images\n    for iter2 in [100,300,500,700]:\n        for iter3 in [100,300,500,700]:\n            resized = img[iter2:dim2[0]+iter2,iter3:dim2[0]+iter3,:]\n            cv2.imwrite(folderlocation + str(img_count) +'_'+filenames[iter1], resized)\n            inverte(resized,folderlocation + str(img_count) +'_i_'+filenames[iter1])\n            img_count = img_count + 1","metadata":{"execution":{"iopub.status.busy":"2022-12-11T04:10:35.446796Z","iopub.execute_input":"2022-12-11T04:10:35.447855Z","iopub.status.idle":"2022-12-11T04:10:36.937401Z","shell.execute_reply.started":"2022-12-11T04:10:35.447804Z","shell.execute_reply":"2022-12-11T04:10:36.936579Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Satellite Images of Water Bodies","metadata":{}},{"cell_type":"code","source":"folderlocation = './data/space/'\n\nPATH = '/kaggle/input/satellite-images-of-water-bodies/Water Bodies Dataset/Images/'\nfilenames = next(os.walk(PATH), (None, None, []))[2]  \nfilenames = sorted(filenames)\n\nimg = cv2.imread(PATH + filenames[1], cv2.IMREAD_UNCHANGED)\nprint('Example Image size: ',img.shape)\n\nfor iter1 in range(300):\n    shutil.copyfile(PATH + filenames[iter1], folderlocation + 'Water'+ filenames[iter1])\n    img = cv2.imread(PATH + filenames[iter1], cv2.IMREAD_UNCHANGED)\n    inverte(img,folderlocation +'Water_i_'+filenames[iter1])\n\nplt.imshow(img)\nplt.axis('off')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-11T04:10:36.938865Z","iopub.execute_input":"2022-12-11T04:10:36.939489Z","iopub.status.idle":"2022-12-11T04:10:41.904814Z","shell.execute_reply.started":"2022-12-11T04:10:36.939443Z","shell.execute_reply":"2022-12-11T04:10:41.903210Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Galaxy Zoo 2: Images","metadata":{}},{"cell_type":"code","source":"folderlocation = './data/space/'\n\nPATH = '/kaggle/input/galaxy-zoo-2-images/images_gz2/images/'\nfilenames = next(os.walk(PATH), (None, None, []))[2]  \nfilenames = sorted(filenames)\n\nimg = cv2.imread(PATH + filenames[1], cv2.IMREAD_UNCHANGED)\nprint('Example Image size: ',img.shape)\n\nfor iter1 in range(300):\n    shutil.copyfile(PATH + filenames[iter1], folderlocation + 'Galaxy'+filenames[iter1])\n    img = cv2.imread(PATH + filenames[iter1], cv2.IMREAD_UNCHANGED)\n    inverte(img,folderlocation +'Galaxy_i_'+filenames[iter1])\n    \nplt.imshow(img)\nplt.axis('off')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-11T04:10:41.907515Z","iopub.execute_input":"2022-12-11T04:10:41.908621Z","iopub.status.idle":"2022-12-11T04:14:07.478833Z","shell.execute_reply.started":"2022-12-11T04:10:41.908555Z","shell.execute_reply":"2022-12-11T04:14:07.477621Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Wood texture samples\nBackground may contain wooden furniture","metadata":{}},{"cell_type":"code","source":"PATH = '/kaggle/input/wood-samples/images/images/'\nfilenames = next(os.walk(PATH), (None, None, []))[2] \n\nfolderlocation = './data/wood/'\nif not os.path.exists(folderlocation):\n    os.mkdir(folderlocation)\n\nfor iter1 in range(200):\n    shutil.copyfile(PATH + filenames[iter1], folderlocation +filenames[iter1])\n    img = cv2.imread(PATH + filenames[iter1], cv2.IMREAD_UNCHANGED)\n    inverte(img,folderlocation +'_i_'+filenames[iter1])","metadata":{"execution":{"iopub.status.busy":"2022-12-11T04:14:07.480382Z","iopub.execute_input":"2022-12-11T04:14:07.480753Z","iopub.status.idle":"2022-12-11T04:14:08.169463Z","shell.execute_reply.started":"2022-12-11T04:14:07.480721Z","shell.execute_reply":"2022-12-11T04:14:08.168115Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Furniture Images Dataset","metadata":{}},{"cell_type":"code","source":"PATH = '/kaggle/input/furniture-images-dataset/furniture_images/furniture_images/'\nfilenames = next(os.walk(PATH), (None, None, []))[2] \nfilenames = sorted(filenames)\n\nfolderlocation = './data/furniture/'\nif not os.path.exists(folderlocation):\n    os.mkdir(folderlocation)\n\nfor iter1 in range(100):\n    shutil.copyfile(PATH + filenames[iter1], folderlocation +filenames[iter1])","metadata":{"execution":{"iopub.status.busy":"2022-12-11T04:14:08.171237Z","iopub.execute_input":"2022-12-11T04:14:08.171616Z","iopub.status.idle":"2022-12-11T04:14:13.488814Z","shell.execute_reply.started":"2022-12-11T04:14:08.171582Z","shell.execute_reply":"2022-12-11T04:14:13.487625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shutil.make_archive('Background_data', 'zip', './data/')\nshutil.rmtree('./data/')","metadata":{"execution":{"iopub.status.busy":"2022-12-11T04:14:13.490242Z","iopub.execute_input":"2022-12-11T04:14:13.490595Z","iopub.status.idle":"2022-12-11T04:14:19.781867Z","shell.execute_reply.started":"2022-12-11T04:14:13.490563Z","shell.execute_reply":"2022-12-11T04:14:19.780399Z"},"trusted":true},"execution_count":null,"outputs":[]}]}