Skip to content

Instantly share code, notes, and snippets.

@revanurambareesh
revanurambareesh / matplotlib_2d3d_subplots.py
Created September 3, 2019 12:43
Multi subplot figure in Matplotlib 2D and 3D
import matplotlib.pyplot as plt
# creates 1x2 subplots that be accessed with ax[0], ax[1]
# 2D subplots
_, ax = plt.subplots(1, 2, figsize=(8, 4))
# example
ax[0].imshow(_im)
# creates 1x2 subplots that be accessed with ax[0], ax[1]
@revanurambareesh
revanurambareesh / mdp-ttt-state.py
Created January 1, 2019 16:21
MDP State object
class State:
def __init__(self, player: Player, state_desc: State_Desc):
# print(state_desc)
assert (len(state_desc) == 9)
self.possible_actions: List = [action[1].name for action in enumerate(Action) if state_desc[action[0]] == '-']
self.p: Dict = {action: Qvalue_Frequency((RewardType(0), 0)) for action in self.possible_actions}
self.v_star = -np.inf
self.state_desc: State_Desc = state_desc
self.policy = None # Represents best action to be taken
self.player: Player = player
# From Tensorflow's documentation:
class SquareTest(tf.test.TestCase):
      def testSquare(self):
        with self.test_session():
          x = tf.square([2, 3])
          self.assertAllEqual(x.eval(), [4, 9])
    if __name__ == '__main__':
      tf.test.main()
@revanurambareesh
revanurambareesh / contour.cs
Created August 5, 2018 11:48
Contour Detection in egmu CV
public Bitmap DetectContours()       
{
    Bitmap colorImage = BMP;
    Bitmap blankImage = new Bitmap(BMP.Width, BMP.Height, BMP.PixelFormat);
    Image<Gray, byte> grayImage = new Image<Gray, byte>(colorImage);
    Image<Bgr, byte> color = new Image<Bgr, byte>(colorImage);
    Image<Bgr, byte> whiteconverter = new Image<Bgr, byte>(blankImage);
    grayImage = grayImage.ThresholdBinary(new Gray(0), new Gray(255));
    grayImage._Not();
    using (MemStorage storage = new MemStorage())
@revanurambareesh
revanurambareesh / morph-op-egmucv.cs
Created August 5, 2018 11:45
Erosion and Dilation in Egmu CV
var element = CvInvoke.GetStructuringElement(ElementShape.Cross, new Size(3, 3), new Point(-1, -1));
Image<Gray, byte> eroded = new Image<Gray, byte>(OriginalImage.Size);
CvInvoke.cvErode(OriginalImage, eroded, element, new Point(-1, -1), 1, BorderType.Reflect, default(MCvScalar));
CvInvoke.Dilate(eroded, temp, element, new Point(-1, -1), 1, BorderType.Reflect, default(MCvScalar));
@revanurambareesh
revanurambareesh / min-graph-plotter.py
Last active August 5, 2018 12:18
Minimal 3D Graph Plotter in matplotlib
import sys
save_movie = False
print('Usage for creating a video: python min-graph-plotter.py --movie')
print('Usage for creating a pic : python min-graph-plotter.py')
def plotequ():
import matplotlib
if save_movie:
matplotlib.use("Agg")