Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Python1

Python programs

Uploaded by

Saji.K. mathai
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python1

Python programs

Uploaded by

Saji.K. mathai
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

**detail of image

import cv2
img=cv2.imread("miya.jpg")
img?

**image size

img=cv2.imread("miya.jpg")
print(img.shape)

** open a file as gray

img=cv2.imread("miya.jpg",0)
print(img.shape)

**open a file with cv2

import cv2
import numpy as np
import matplotlib.pyplot as plt
img=cv2.imread("miya.jpg")
cv2.imshow("image",img)
cv2.waitKey(0)
cv2.destroyALLwindows()

**open file with open cv and plot with matplot

import cv2
import matplotlib.pyplot as plt
img=cv2.imread("miya.jpg")
plt.imshow(cv2.cvtColor(img,cv2.COLOR_BGR2RGB))
plt.title("Chameleon")
plt.axis("off")
plt.show()
**convert to RGB

import cv2
import matplotlib.pyplot as plt
import numpy as np
img=cv2.imread("miya.jpg")
plt.imshow(cv2.cvtColor(img,cv2.COLOR_BGR2RGB))
plt.axis("on")
plt.title("chamelon")
plt.show()

** gray scale

import matplotlib.pyplot as plt


img_gray=cv2.imread("miya.jpg",0)
plt.imshow(img_gray,cmap='gray')
plt.axis("off")
plt.show()

**total pixels

import cv2
import matplotlib.pyplot as plt
import numpy as np
img=cv2.imread("miya.jpg")
plt.imshow(cv2.cvtColor(img,cv2.COLOR_BGR2RGB))
plt.axis("on")
plt.title("chamelon")
plt.show()
print(img.shape)
[B,G,R]=img[100,100]
print('R=',R,'G=',G,'B=',B)
**cropping an image
import cv2
import matplotlib.pyplot as plt
image=cv2.imread("miya.jpg")
cropped_image=image[75:350, 0:350]
cropped_image_rgb=cv2.cvtColor(cropped_image,cv2.COLOR_BGR2RGB)
plt.imshow(cropped_image_rgb)
plt.axis("off")
plt.title("chamelon 2")
plt.show()

**print a program to read a csv file and print info about the file

import pandas as pnd


marks=pnd.read_csv("marks.csv")----------------->(link to be put of the location of file)
print(marks.head())

**to print the first 5 lines

import pandas as pnd


marks=pnd.read_csv("marks.csv")----------------->(link to be put of the location of file)
print(marks.head(5))

**sort by head

import pandas as pnd


marks=pnd.read_csv("marks.csv")----------------->(link to be put of the location of file)
print(marks.head(5))
sorted_info=marks.sort_values(by=["Name"])
print(sorted_info.head(5))
** statistics

import statistics
marks=[40,35,6,98,24,69,39,20]

mean=statistics.mean(marks)
median=statistics.median(marks)
mode=statistics.mode(marks)
stdev=statistics.stdev(marks)
variance=statistics.variance(marks)
print("Mean",mean)
print("Median",median)
print("Mode",mode)
print("Standard deviation",stdev)
print("Variance",variance)

**scatter plot graph

import matplotlib.pyplot as plt


name=['ravi','shivesh','maria']
marks=[90,55,100]
plt.scatter(name,marks,color='red',marker='s')
plt.xlabel('name')
plt.ylabel('marks')
plt.title('marks obtained')
plt.show

**bar graph
import matplotlib.pyplot as plt
name=['ravi','shivesh','maria']
marks=[90,55,100]
plt.bar(name,marks,color='green')
plt.xlabel('name')
plt.ylabel('marks')
plt.title('marks obtained')
plt.show
**line graph
import matplotlib.pyplot as plt
name=['ravi','shivesh','maria']
marks=[90,55,100]
plt.plot(name,marks,color='green')
plt.xlabel('name')
plt.ylabel('marks')
plt.show

**histogram
import matplotlib.pyplot as plt
import numpy as np
girls=[35 , 98 , 67 , 55 , 66 , 5]
bins=[10 , 20 , 30 , 40 , 50 , 60 , 70]
plt.hist(girls,bins=bins,color='m')
plt.xlabel('Terms')
plt.ylabel('score')
plt.title("scores of students")
plt.show()

**double bar graph

import matplotlib.pyplot as plt


import numpy as np
girls=[45,55,50,60]
boys=[40,50,45,55]
Terms=['T1','T2','T3','T4']
x=np.array([0,1,2,3])
plt.bar(x,boys,width=0.4,label='Boys')
plt.bar(x+0.4,girls,width=0.4,label='Girls')
plt.xlabel('Terms')
plt.ylabel('score')
plt.title("scores of students")
plt.legend()
plt.xticks(x + 0.2,Terms)
plt.show()
x=float(input("enter the first number:"))
y=float(input("enter the second number:"))

n=0
if x>y:
n=x-y
else:
n=y-x
if n <= 0.01:
print('Close')
else:
print('Not Close')

You might also like