Skip to content

Instantly share code, notes, and snippets.

@ashnair1
ashnair1 / size_comparison.py
Created May 8, 2019 07:47
Comparing size of objects with respect to image
"""
Script for visualising the size comparison between the object and the image to determine accurate anchor sizes
"""
from PIL import Image
import numpy as np
img_size = (1024,1024)
obj_size = (16,16)
@ashnair1
ashnair1 / image_slicer.py
Last active May 8, 2019 08:49
Script to slice image into a set number of tiles
import image_slicer
from PIL import Image
def parser():
arg_parser = argparse.ArgumentParser('Image Slicer')
arg_parser.add_argument('--image', help='Image to be sliced')
arg_parser.add_argument('--num_tiles', help='Number of tiles')
arg_parser.add_argument('--save_tiles', help="Save tiles",action='store_true')
arg_parser.add_argument('--tiles_dir',help="Directory to store tiles",type=str)
return arg_parser.parse_args()
@ashnair1
ashnair1 / coco_cat_count.py
Last active May 9, 2019 08:02
Count occurrences of categories from COCO annotation format
import numpy as np
import json
import matplotlib.pyplot as plt
from collections import Counter
# For jupyter notebook
#%matplotlib inline
# TODO: Clean up this code
@ashnair1
ashnair1 / dota2coco.py
Last active August 5, 2019 05:50
DOTA2COCO_Converter
# -*- coding:utf-8 -*-
import os
import cv2
import json
import pprint
import numpy as np
from PIL import Image
category_dict = {'plane': 0, 'ship': 1, 'storage-tank': 2, 'baseball-diamond': 3, 'tennis-court': 4, 'basketball-court': 5,
'ground-track-field': 6, 'harbor': 7, 'bridge': 8, 'small-vehicle': 9, 'large-vehicle': 10,
@ashnair1
ashnair1 / Install NVIDIA Driver and CUDA.md
Created August 14, 2019 15:46 — forked from wangruohui/Install NVIDIA Driver and CUDA.md
Install NVIDIA Driver and CUDA on Ubuntu / CentOS / Fedora Linux OS
@ashnair1
ashnair1 / merge-geojsons.py
Last active August 28, 2020 18:54 — forked from themiurgo/merge-geojsons.py
Merge two or more geojson files.
from json import load, dump
from argparse import ArgumentParser
from re import compile
import sys
import os
parser = ArgumentParser(description="Group (merge) multiple GeoJSON files.")
defaults = dict(outfile=sys.stdout)
@ashnair1
ashnair1 / gdal_commands.md
Last active May 7, 2024 12:08
Useful gdal commands

1. Rescale specfic bands and write them to output tiff

gdal_translate -ot Byte -b 5 -b 3 -b 2 -scale_1 0 1970 0 255 -scale_2 0 1860 0 255 -scale_3 0 1174 0 255 WV.TIF WV_RGB.TIF

We take bands 5 (red), 3 (green) and 2(blue), scale them to 8 bit range and write it to an output file. Things to note:

a. Output scale by default is 0 to 255, so there's no real reason to specify. 
b. Once we pick the bands, they are thereafter referred w.r.t output. This is why we specify `scale_1` to rescale band 5 because band 5 in the input is band 1 of output.
import os
import shutil
src_dir = "./Files"
dst_dir = "./Result"
"""
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.