https://subinze.tistory.com/9

'Python' 카테고리의 다른 글

xlsx 데이터 불러와서 Data smoothing 하기  (0) 2024.03.30
index 시작값 수정하기  (0) 2022.02.14
Python에서 행과 열 데이터 바꾸기  (0) 2022.02.09
Ununtu 20.04에서 CUDA 설치하기  (0) 2021.11.05
Python3.9 - IDLE 설치  (0) 2021.08.30

361_2.xlsx
0.02MB

import pandas as pd
import matplotlib.pyplot as plt

def smooth_data(data, factor):
    smoothed_data = data.rolling(window=factor, min_periods=1).mean()
    return smoothed_data

# 데이터 불러오기
file_path = '361_2.xlsx'
data = pd.read_excel(file_path)

# 스무딩(factor 조정 가능)
factor = 5
smoothed_data_1 = smooth_data(data['Data-1'], factor)
smoothed_data_2 = smooth_data(data['Data-2'], factor)

# 데이터 번호 열 추가
data.insert(0, 'No.', range(1, len(data) + 1))

# 스무딩된 데이터를 'sm.xlsx' 파일에 저장
output_file = 'sm_out.xlsx'
with pd.ExcelWriter(output_file) as writer:
    data[['No.']].to_excel(writer, index=False)
    pd.DataFrame({'Smoothed Data-1 (Factor={})'.format(factor): smoothed_data_1}).to_excel(writer, index=False, startcol=1)
    pd.DataFrame({'Smoothed Data-2 (Factor={})'.format(factor): smoothed_data_2}).to_excel(writer, index=False, startcol=2)

# 그래프로 출력
plt.plot(data['No.'], data['Data-1'], label='Data-1 (Original)', color='blue', linestyle='--', linewidth=1)
plt.plot(data['No.'], smoothed_data_1, label=f'Data-1 Smoothed (Factor={factor})', color='blue', linestyle='-', linewidth=1)
plt.plot(data['No.'], data['Data-2'], label='Data-2 (Original)', color='red', linestyle='--', linewidth=1)
plt.plot(data['No.'], smoothed_data_2, label=f'Data-2 Smoothed (Factor={factor})', color='red', linestyle='-', linewidth=1)
plt.xlabel('No.')
plt.ylabel('Value')
plt.title('Original vs Smoothed Data')
plt.legend()
plt.grid(True)
plt.show()

'Python' 카테고리의 다른 글

코딩 테스트 (참고사이트)  (0) 2024.04.18
index 시작값 수정하기  (0) 2022.02.14
Python에서 행과 열 데이터 바꾸기  (0) 2022.02.09
Ununtu 20.04에서 CUDA 설치하기  (0) 2021.11.05
Python3.9 - IDLE 설치  (0) 2021.08.30

rescale 조정하여 output.png 파일로 저장

import cv2

rescale = 6

def resize_image(input_path, output_path, scale_factor=rescale):
    image = cv2.imread(input_path)
    height, width = image.shape[:2]
    new_width = int(width * scale_factor)
    new_height = int(height * scale_factor)
    resized_image = cv2.resize(image, (new_width, new_height))
    cv2.imwrite(output_path, resized_image)

# 입력 파일 경로
input_file_path = "input.png"

# 출력 파일 경로
output_file_path = "output.png"

# 이미지 크기를 n배로 저장
resize_image(input_file_path, output_file_path, scale_factor=rescale)

'Python > Image Super Resolution' 카테고리의 다른 글

image MSE, RMSE, PSNR 계산  (0) 2024.03.29

Quality = 80 %
Quality = 100 %

 

# ===== 방법-1 =====

import cv2
img1 = cv2.imread('input.jpg')
img2 = cv2.imread('input_80p.jpg')
psnr = cv2.PSNR(img1, img2)
print(f"PSNR: {psnr}")


#%%
# ===== 방법-2 =====

import cv2
import numpy as np

def calculate_metrics(original_image_path, compressed_image_path):
    # 원본 이미지와 압축된 이미지 불러오기
    original_image = cv2.imread(original_image_path)
    compressed_image = cv2.imread(compressed_image_path)
    
    # 이미지가 같은 크기인지 확인
    if original_image.shape != compressed_image.shape:
        print("이미지 크기가 다릅니다.")
        return
    
    # MSE 계산
    mse = np.mean((original_image - compressed_image) ** 2)
    
    # RMSE 계산
    rmse = np.sqrt(mse)
    
    # PSNR 계산
    max_pixel_value = 255.0
    psnr = 20 * np.log10(max_pixel_value / rmse)
    
    return mse, rmse, psnr

# 원본 이미지 경로와 압축된 이미지 경로 설정
original_image_path = "input.jpg"
compressed_image_path = "input_80p.jpg"

# 이미지 품질 측정 메트릭 계산
mse, rmse, psnr = calculate_metrics(original_image_path, compressed_image_path)

# 결과 출력
print("")
print(f"MSE: {mse}")
print(f"RMSE: {rmse}")
print(f"PSNR: {psnr}")
print("")

'Python > Image Super Resolution' 카테고리의 다른 글

이미지 파일을 n배로 저장하는 방법  (0) 2024.03.30

Logitech 무선마우스 오프라인 설치 프로그램

 

◆ URL
https://prosupport.logi.com/hc/en-us/articles/10991109278871-Logitech-Options-Offline-Installer

◆ 파일
https://download01.logi.com/web/ftp/pub/techsupport/optionsplus/logioptionsplus_installer_offline.exe

### noise remove ###

import numpy as np
import soundfile as sf
import matplotlib.pyplot as plt
from scipy.signal import freqz

""" READ FILE """
data, samplerate = sf.read('example_noise.wav')  ## wav file name

""" CONSTANTS """
L = 101
M = L - 1
# fc = 7500 # in HZ


### value control ###
fc = 600 # in HZ
### value control ###


fr = np.ones(L)

# Produce h[n] values of 1 for default
H = np.ones(M)
W = np.ones(M)
HW = np.ones(M)

""" FUNCTIONS """
# Function for the low Pass Filter
def low_pass(n):
    ft = fc / samplerate
    # Determine filter weights
    if(n != (M/2)):
        filter_weight = np.sin(2 * np.pi * ft * (n - M/2)) / (np.pi * (n - M/2))
    else:
        filter_weight = 2 * ft
    # Return weight
    return filter_weight

def windowing(n):
    # Create w(n) value
    window = 0.54 - 0.46 * np.cos((2*np.pi*n)/M)
    return window

# Populate frequency array
for i in range(M):
    H[i] = low_pass(i)
    
# Get frequency response before applying window
x, y = freqz(H, 1)
plt.plot(x, abs(y))

# Populate window array
for k in range(M):
    W[k] = windowing(k)
    
# Apply filter coefficients to produce h[n]
HW = np.multiply(H, W)

# Plot the frequency response of h[n]
x, y = freqz(HW, 1)
plt.plot(x, abs(y))

# Output new song without fuzz
clean_file = np.convolve(data, HW)
sf.write('OUTPUT.wav', clean_file, samplerate)

to Top