Skip to content

Instantly share code, notes, and snippets.

def FrontierSimplePower12(x):
if x <= 500:
return 53
else:
return 53 + (x-500)*(0.1286+0.038447)
def constellation(x):
rate = 0.074
return 3.42+(0.038447+rate)*x
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
def distance(point1,point2):
return sqrt((point1[0]-point2[0])**2 + (point1[1]-point2[1])**2)
def gaussianLP(D0,imgShape):
base = np.zeros(imgShape[:2])
rows, cols = imgShape[:2]
center = (rows/2,cols/2)
for x in range(cols):
for y in range(rows):
base[y,x] = exp(((-distance((y,x),center)**2)/(2*(D0**2))))
def distance(point1,point2):
return sqrt((point1[0]-point2[0])**2 + (point1[1]-point2[1])**2)
def butterworthLP(D0,imgShape,n):
base = np.zeros(imgShape[:2])
rows, cols = imgShape[:2]
center = (rows/2,cols/2)
for x in range(cols):
for y in range(rows):
base[y,x] = 1/(1+(distance((y,x),center)/D0)**(2*n))
def distance(point1,point2):
return sqrt((point1[0]-point2[0])**2 + (point1[1]-point2[1])**2)
def idealFilterLP(D0,imgShape):
base = np.zeros(imgShape[:2])
rows, cols = imgShape[:2]
center = (rows/2,cols/2)
for x in range(cols):
for y in range(rows):
if distance((y,x),center) < D0:
import cv2
import numpy as np
import matplotlib.pyplot as plt
plt.figure(figsize=(6.4*5, 4.8*5), constrained_layout=False)
img_c1 = cv2.imread("left01.jpg", 0)
img_c2 = np.fft.fft2(img_c1)
img_c3 = np.fft.fftshift(img_c2)
img_c4 = np.fft.ifftshift(img_c3)
import bluetooth
import subprocess
class BluetoothComm:
def __init__(self):
self.server_socket=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
port = 1
self.server_socket.bind(("",port))
self.server_socket.listen(1)
self.client_socket,address = self.server_socket.accept()
print("Accepted connection from ",address)
@HiCraigChen
HiCraigChen / bluetooth_test.py
Last active August 13, 2020 12:54
Enable bluetooth socket (server socket) to communicate with other device (client socket) using python
import bluetooth
server_socket=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
port = 1
server_socket.bind(("",port))
server_socket.listen(1)
client_socket,address = server_socket.accept()
print("Accepted connection from ",address)
while True:
@HiCraigChen
HiCraigChen / app.py
Last active February 9, 2023 13:39
Convert PDF to image using Python with pdf2image library
from chalice import Chalice, Response
from pdf2image import convert_from_bytes
import os
from io import BytesIO
app = Chalice(app_name='pdf2image')
@app.route('/')
def index():
@HiCraigChen
HiCraigChen / app.py
Last active September 25, 2019 01:10
Convert PDF to image using Python wand library
from wand.image import Image
import os
# Download and read pdf file
os.system("curl https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf -o /tmp/file.pdf")
f = open('/tmp/file.pdf','rb')
infile = f.read()
f.close()
with Image(blob=infile,resolution=150) as img_pdf: