Skip to content

Instantly share code, notes, and snippets.

View ritwikraha's full-sized avatar
🎲
learning is probabilistic.

Ritwik Raha ritwikraha

🎲
learning is probabilistic.
View GitHub Profile
@ritwikraha
ritwikraha / getsector.py
Last active June 22, 2019 19:28
code snippet to create polygon from camera point
import cv2
import numpy as np
clickPt = []
def clickDetect(event, x, y, flags, param):
global clickPt
if event == cv2.EVENT_LBUTTONDOWN:
clickPt = [(x, y)]
import cv2
import numpy as np
# import an image
image=cv2.imread("fayah.jpg")
# take x,y from getsector.py
image[x,y]=[0,0,255]
# Save
%% first we load the MNIST dataset
digitDatasetPath = fullfile(matlabroot,'toolbox','nnet','nndemos', ...
'nndatasets','DigitDataset');
imds = imageDatastore(digitDatasetPath, ...
'IncludeSubfolders',true,'LabelSource','foldernames');
%% visualizing the image data
figure;
permute = randperm(10000,10);
for i = 1:10
subplot(2,5,i);
import cv2
import matplotlib.pyplot as plt
# reading the smooth image and converting it into RGB color space
image_smooth = cv2.cvtColor(cv2.imread('smooth.jpg'),cv2.COLOR_BGR2RGB)
# calculating edges from the smooth image
edge_smooth= cv2.cvtColor(cv2.Canny(image_smooth, 100, 250),cv2.COLOR_BGR2RGB)
# reading a normal sharp image and converting the color space
image_sharp = cv2.cvtColor(cv2.imread('sharp.jpg'),cv2.COLOR_BGR2RGB)
# claculating the edges from the image
edge_sharp= cv2.cvtColor(cv2.Canny(image_sharp, 100, 250),cv2.COLOR_BGR2RGB)
grayImage = imread('cameraman.tif');
subplot(2, 1, 1);
imshow(grayImage);
subplot(2, 1, 2);
histObject = histogram(grayImage, 256, 'Normalization', 'probability')
grid on;
xlabel('Gray Level', 'FontSize', 20);
ylabel('Probability', 'FontSize', 20);
% Extract probabililty of each gray level into a vector "p".
p = histObject.Values;
offsetsEdge=[zeros(40,1)(1:40)'];
glcms=graycomatrix(I,'Offset',offsetsEdge);
stats=graycoprops(glcm)
%[m,n]= size(I)
% using all the statistical texture information
% and plotting them
offsetsEdge = [zeros(40,1)(1:40)];
glcms = graycomatrix(I,'Offset',offsetsEdge);
stats = graycoprops(glcm)
stats.Contrast
stats.Correlation
stats.Energy
K=rangefilt(I);
J=stdfilt(I);
Jen=entropyfilt(I);
% finding the correlation between the original image
% and the maximum available texture information
% alternatively use 'corrcoef'
R =corr2(I,max(K,J,Jen));
% plotting the power spectral density of the image available
% using the psd plot to obtain further information
psd = imagesc(log10(abs(fftshift(fft2(I))).^2))
mesh(psd);
se = strel(3,3);
basic_gradient = imdilate(I,se)- imerode(I,se);
external_gradient= I-basic_gradient;
peakpsnr = psnr(external_gradient,I);