Skip to content

Instantly share code, notes, and snippets.

@anilsathyan7
anilsathyan7 / convert_to_numpy.py
Last active December 31, 2023 05:11
Convert all images in a directory to ".npy" format
from PIL import Image
import os, sys
import cv2
import numpy as np
'''
Converts all images in a directory to '.npy' format.
Use np.save and np.load to save and load the images.
Use it for training your neural networks in ML/DL projects.
'''
@anilsathyan7
anilsathyan7 / revrsstr.bf
Last active July 31, 2022 23:49
Brainfuck reverse a string
,
[
[<]<+
>>[>]
,
]
<
[.<]
@anilsathyan7
anilsathyan7 / lenofip.bf
Last active June 25, 2021 16:17
Brainfuck Length of Input string
+++++ +++
[
> +++++ +
< -
]
>>>
,.
[
[<]<+
>>[>]
@anilsathyan7
anilsathyan7 / helloworld.bf
Last active May 6, 2020 23:01
Brain fuck hello-world program
+++++ +++++ initialize counter (cell #0) to 10
[ set the next four cells to 70 100 30 and 10 respectively
> +++++ ++ add 7 to cell #1
> +++++ +++++ add 10 to cell #2
> +++ add 3 to cell #3
> + add 1 to cell #4
<<<< - decrement counter (cell #0)
]
> ++ . print 'H' (H = ASC (72))
@anilsathyan7
anilsathyan7 / numbamatmul.py
Created July 31, 2017 15:09
Python numba matrix multiplication
import time
import numba
from numba import jit
import numpy as np
#input matrices
matrix1 = np.random.rand(30,30)
matrix2 = np.random.rand(30,30)
rmatrix = np.zeros(shape=(30,30))
@anilsathyan7
anilsathyan7 / README.md
Last active October 24, 2019 08:27
Cluster similar shapes in an image using hu moments, with the help of opencv and scikit-learn

Sample Output

Similar shapes in the input image(left) are grouped into same clusters, using hu moments. Members of the same cluster are shown with same coloured bounding boxes in the output image(right).

@anilsathyan7
anilsathyan7 / README.md
Last active October 24, 2019 08:23
Cluster similar patches in an image using ssim, with the help of opencv and scikit-learn

Sample Output

Similar patches or objects in the input image(left) are grouped into same clusters, using Structural Similarity Index(SSIM). Members of the same cluster are shown with same coloured bounding boxes in the output image(right).

@anilsathyan7
anilsathyan7 / image_scramble.py
Last active August 6, 2019 10:56
Scramble-Unscramble - Shuffles images into fixed size patches to create a jigsaw puzzle.A key-map dictionary is used to recover the shuffled image.
import numpy as np
from PIL import Image
from imageio import imsave
from skimage.util.shape import view_as_blocks
# Global shuffle key
map={}
'''
Args:-
@anilsathyan7
anilsathyan7 / synthetic.py
Last active July 14, 2019 18:04
Synthetic image composting as data-augmentation for semantic segmentation datasets
from PIL import Image
import os, sys
from scipy.misc import imsave
import cv2
import numpy as np
import random
import argparse
'''
Creates synthetic images with custom backgrounds, using the default images and masks in the dataset.
@anilsathyan7
anilsathyan7 / image_capture.py
Created May 4, 2018 21:21
A program in python for capturing images from webcam, using OpenCV
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
i=1
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Operations on the frame