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

■ ■ ■ ■ ■ 참고 ■ ■ ■ ■ ■

(base) 에서 원하는 tensorflow 버전으로 설치

v1 : conda install tensorflow==1.15.0

v1 : conda install tensorflow==2.~~~~~

 

■ ■ ■ ■ ■ 참고 ■ ■ ■ ■ ■

cudatoolkit 설치시 오류가 발생하면 cudnn 설치를 먼저 해주는 것도 좋다.
이 경우, cudnn7.6이 설치되면서 cudatoolkit10.1도 함께 설치된다.

 

https://www.tensorflow.org/install/source_windows?hl=ko

 

Windows의 소스에서 빌드,Windows의 소스에서 빌드  |  TensorFlow

이 페이지는 Cloud Translation API를 통해 번역되었습니다. Switch to English Windows의 소스에서 빌드,Windows의 소스에서 빌드 컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하

www.tensorflow.org

 

conda install tensorflow-gpu==1.15.0
conda install -c anaconda cudatoolkit==10.1
conda install -c anaconda cudnn==7.4


conda install tensorflow==2.10
conda install -c anaconda cudatoolkit==10.1
conda install -c anaconda cudnn==8.1

 

====================================================================

 

■참고■ https://www.tensorflow.org/install/pip#windows-native

TensorFlow 2.10 은 기본 Windows 에서 GPU를 지원하는 마지막 TensorFlow 릴리스였습니다.
TensorFlow 2.11 부터 WSL2에 TensorFlow 를 설치하거나, tensorflow-cpu 를 설치하고 선택적으로 TensorFlow-DirectML-Plugin 을 시도해야 합니다.

 

==============================

 

■ Anaconda Prompt (anaconda3)  <== 관리자 권한으로 실행

■ python -V (버전 확인)

■ Tensorflow 설치
1) pip install -upgrade pip
2) conda create -n tensorflow pip python=3.9 (가상환경 생성)
3) conda activate tensorflow (가상환경으로 이동)
4) Tensorflow 설치
    - GPU 버젼 : pip install --ignore-installed --upgrade tensorflow-gpu
    - CPU 버젼 : pip install --ignore-installed --upgrade tensorflow-cpu

■ Tensorflow 설치 확인
1) Anaconda Prompt (anaconda3) prompt 상에서
2) python
3) import tensorflow as tf
4) print(tf.__version__) 입력

 

 

================

 

아나콘다 설치 후 Anaconda Prompt에서 순서대로 실행한다.

conda update conda

conda update --all

conda create -n tensorflow python=3.8

conda env list

activate tensorflow

python --version

conda --version

pip install --upgrade pip

pip install tensorflow

 

※ 가상환경 삭제

conda env remove -n 가상환경이름 --all



출처: https://leeted.tistory.com/211 [이태원 블로그]

0
1
2
3



1
2
3
4

로 수정하는 방법

aaa.index=aaa.index + 1
aaa.columns = aaa.columns + 1

ex)

bbb = pd.DataFrame(aaa)
bbb.index=bbb.index + 1           # index(행) 번호 + 1
bbb.columns = bbb.columns + 1     # columns(열) 번호 + 1

bbb.to_excel('output.xlsx', index=True, header=True, encoding="utf-8")

to Top