程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Format conversion of raw image Python medical image

編輯:Python

Many medical images are raw Format saved ,raw At the same time, it is also the original format of the photos taken by the SLR camera .

RAW Images :CMOS perhaps CCD The image sensor converts the captured light source signal into the original data of the digital signal .

Recently used pytorch When processing ophthalmic medical images , Need to put raw Convert to jpg. because raw Generally, images cannot be processed directly , So use Python Format conversion . After searching, it's very complicated , What to get raw Data format , The length and width of the picture , As a result, I tried it myself , direct opencv The result is , So record it , There is no in-depth study , I look forward to further research in the future raw Image processing .

Core code

img = cv2.imread(filePath)
cv2.imwrite(filename, img)

Complete code :jpg.py

import numpy as np
import os
import cv2
import shutil
from PIL import Image
def searchDirFile(rootDir,saveDir):
for dir_or_file in os.listdir(rootDir):
try:
filePath = os.path.join(rootDir, dir_or_file)
# Determine if it is a file
if os.path.isfile(filePath):
# If it is a document, then judge whether it is based on .jpg ending , If not, skip this cycle
if os.path.basename(filePath).endswith('.raw'):
print('imgBox fileName is: '+os.path.basename(filePath))
# Copy jpg File to the directory you want to save
# shutil.copyfile(filePath,os.path.join(saveDir,os.path.basename(filePath)))
img = cv2.imread(filePath)
path2 = filePath.split('/')[2]
path = f'{saveDir}/{path2}'
# print(path)
if not os.path.exists(path):
os.makedirs(path)
filename = os.path.splitext(os.path.basename(filePath))[0] + ".jpg"
filename = os.path.join(path, filename)
print('filename is: '+filename)
cv2.imwrite(filename, img)
else:
continue
# If it's a dir, Then call this function again , Incoming current directory , Recursive processing .
elif os.path.isdir(filePath):
searchDirFile(filePath, saveDir)
else: print('not file and dir '+os.path.basename(filePath))
except:
continue
if __name__ == '__main__':
rootDir = './Images'
saveDir = './jpg'
searchDirFile(rootDir, saveDir)
print("the end !!!")


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved