Skip to content

Instantly share code, notes, and snippets.

View Yuktha-Majella's full-sized avatar

Yuktha-Majella

View GitHub Profile
#Splitting image into Blue, Green, Red channels
#Method 1
b,g,r = cv2.split(img)
#Method 2
b = img[:,:,0]
g = img[:,:,1]
r = img[:,:,2]
vis2 = np.concatenate((b, g, r), axis=1)
#Image ROI
img_roi = img.copy()
ball = img_roi[310:370, 350:405]
img_roi[120:180, 120:175] = ball
vis1 = np.concatenate((img, img_roi), axis=1)
cv2.imshow('Original Image vs Image with copied ROI', vis1)
cv2.waitKey(0)
cv2.destroyAllWindows()
#Accessing Image Properties
print("Shape of the Image: ", img.shape)
print("Total number of pixels in images: ", img.size)
print("Datatype of the images: ", img.dtype)
#Acessing Red value in coordinates (50, 50)
print("Pixel value of Red in (50,50) coordinate: ", img_mod1.item(50,50,2))
# modifying Red value in coordinates (50, 50)
img_mod1.itemset((50,50,2), 225)
print("Pixel value of Red in (50,50) coordinate after modification: ", img_mod1.item(50,50,2))
cv2.imshow('Billiards Modified', img_mod1)
cv2.waitKey(0)
cv2.destroyAllWindows()
#Modifying pixel values
img_mod1 = img.copy()
img_mod1[100,100] = [255,255,255]
print("Pixel value in (100,100) coordinate after modification: ", img_mod1[100,100] )
cv2.imshow('Billiards Modified', img_mod1)
cv2.waitKey(0)
cv2.destroyAllWindows()
#Accessing BGR value of pixel in coordinates 100,100
pixel = img[100,100]
print("Pixel value in (100,100) coordinate: ", pixel)
#Accessing blue, Red, Green pixel individually
blue = img[100,100,0]
green = img[100,100,1]
red = img[100,100,2]
print("Pixel value of Blue in (100,100) coordinate: ", blue)
@Yuktha-Majella
Yuktha-Majella / ImageOperations_ReadImage
Created October 26, 2021 14:26
Reading an image using cv2
import numpy as np
import cv2
img = cv2.imread('C:\\Users\\Admin\\Downloads\\operations on images\\Billiards.jpg')
@Yuktha-Majella
Yuktha-Majella / summarize_text
Created October 21, 2021 21:04
Using summarize from gensim.summarization, we are summarizing a text
import gensim
from gensim.summarization import summarize
summary = summarize(text)
print(summary)
doc_lda_test = lda_model[test_corpus]
print("Topic Distribution in the test article: ", doc_lda_test[0])
@Yuktha-Majella
Yuktha-Majella / LDA_test_article
Last active October 21, 2021 21:45
Predicting the topic for an unseen document using LDA
test_article = "wipro beats forecasts once again wipro india s thirdbiggest software firm has reported a 60 percent rise in profit topping market expectations net income in the last quarter was 43bn rupees dollar 98m 52m against 27bn a year earlier profit had been forecast to be 41bn rupees wipro offers services such as call centres to foreign clients and has worked for more than half of the companies on the fortune 500 list wipro said demand was strong allowing it to increase the prices it charged on the face of it the results don t look very exciting said apurva shah an analyst at askraymond james but the guidance is positive and pricing going up is good news thirdquarter sales rose 34 percent to 209bn rupees one problem identified by wipro was the high turnover of its staff it said that 90 percent of employees at its business process outsourcing operations had had to be replaced we have to get that under control said vicechairman vivek paul wipro is majority owned by india s richest man azim premji"