Python
ericohe
AI工程师
展开
-
Python 读取默认配置文件
编写配置文件[Defaults]option=Hello world!读取配置文件import argparseimport configparserimport sysdef main(argv=None): # Do argv default this way, as doing it in the functional # declaration sets it at compile time. if argv is None: ...原创 2022-04-30 11:11:46 · 483 阅读 · 0 评论 -
Convert Python Class Object to JSON string
适合string + object混合的情况下import jsonclass Laptop: name = 'My Laptop' processor = 'Intel Core' #create objectlaptop1 = Laptop()laptop1.name = 'Dell Alienware'laptop1.processor = 'Intel Core i7'#convert to JSON stringjsonStr = json.dumps(lapt..原创 2021-11-04 17:10:28 · 348 阅读 · 0 评论 -
python 产生并使用requirements.txt
产生pip3 freeze > requirements.txt使用pip3 install -r requirements.txt原创 2021-11-03 16:24:10 · 123 阅读 · 0 评论 -
python显示DICOM中overlay数据
代码:#!/usr/bin/env pythonimport numpy as npimport pydicomimport matplotlib.pyplot as pltds = pydicom.dcmread("MR-SIEMENS-DICOM-WithOverlays.dcm")overlay_data = ds[0x60003000].valuerows = ds[0x60000010].valuecols = ds[0x60000011].valueoverlay..原创 2021-08-06 15:22:05 · 666 阅读 · 2 评论 -
医学影像数据-mhd,nii与DICOM相互转换
mhd转换为Nifti / niiimport SimpleITK as sitkimg = sitk.ReadImage("input.mha")sitk.WriteImage(img, "output.nii")原创 2021-07-30 17:20:24 · 6549 阅读 · 3 评论 -
python 调用多个文件(Unit Test),返回结果
代码#coding=utf-8import osdef run_cmd(ut): #print(ut) val = os.system(ut) print (val)#"msg":"OK","data"def call_cmd(ut): str = os.popen(ut).read() a = str.split("\n") ret = '' for b in a: print (b) end ..原创 2021-07-30 14:24:42 · 372 阅读 · 2 评论 -
python opencv 图像相减(原始图像与梯度图像)
import cv2import numpy as npimport matplotlib.pyplot as pltimport sysimg1 = cv2.imread(file1)img2 = cv2.imread(file2)size = 512img1 = cv2.fastNlMeansDenoisingColored(img1,None,10,10,7,21)img2 = cv2.fastNlMeansDenoisingColored(img2,None,10,10,7...原创 2021-02-08 13:57:22 · 1190 阅读 · 0 评论 -
python opencv 图像配准与比较
代码from skimage import ioimport cv2 as cvimport numpy as npimport matplotlib.pyplot as pltimg_path1 = '2_HE_maxarea.png'img_path2 = '2_IHC_maxarea.png'img1 = io.imread(img_path1)img2 = io.imread(img_path2)img1 = np.uint8(img1)img2 = np.u...原创 2021-02-08 13:51:26 · 2837 阅读 · 1 评论 -
python实现医学病理图片(SVS格式)的格式转换
# svs_split.pyimport pyvipsimport sys filepath = sys.argv[1] img = pyvips.Image.new_from_file(filepath, access='sequential')series = filepath[0:len(filepath) -3]img.dzsave(series)pythonsvs_split.py test.svs执行以上代码后,会生成两份文件,分别是:test.dzi,tes...原创 2021-02-08 13:41:02 · 3552 阅读 · 2 评论 -
Python nii文件转vtk文件
import vtkimport sysreader = vtk.vtkNIFTIImageReader()reader.SetFileName(sys.argv[1])reader.Update()print (reader)contour=vtk.vtkMarchingCubes() contour.SetInputData(reader.GetOutput())contour.ComputeNormalsOn()contour.ComputeGradientsOn()...原创 2021-02-04 18:10:23 · 1618 阅读 · 4 评论 -
python DICOM文件转mha/mhd
pip3 install SimpleITKpip3 install opencv-python原创 2020-12-31 10:50:58 · 1994 阅读 · 4 评论 -
python重命名文件夹下的文件
# -*- coding=utf-8 -*-import globimport sysimport oshave_numpy = Trueinputdir = r'D:/TestData/Dicom/'#outdir = 'jpg/'#os.mkdir(outdir)test_list = [os.path.basename(x) for x in glob.glob(inputdir + './*.dcm')]#print(test_list)for f in test_.原创 2020-07-17 16:10:25 · 195 阅读 · 0 评论 -
基于pydicom的CT图像窗宽窗位调节与转化为jpg图像
# -*- coding=utf-8 -*-import matplotlib.pyplot as pltimport pydicomimport pydicom.uidimport sysimport PIL.Image as Imagefrom PyQt5 import QtGuiimport oshave_numpy = Truetry: import numpyexcept ImportError: have_numpy = False raise.原创 2020-07-17 15:37:13 · 1951 阅读 · 0 评论 -
python下使用pydicom将.dcm文件转化为jpg格式
# Convert DICOM to jpg via openCVimport cv2import osimport pydicomimport globimport numpy as npinputdir = r'input'outdir = 'jpg/'#os.mkdir(outdir)test_list = [os.path.basename(x) for x in glob.glob(inputdir + './*.dcm')]#print(test_list)f...原创 2020-07-15 11:05:06 · 778 阅读 · 0 评论 -
Python 调用C++,返回char*
C++代码int Test( const char* input, char** output) { std::string str("From C++") strcpy (*output,str.c_str()); output[str...原创 2020-01-14 10:10:22 · 1379 阅读 · 0 评论 -
Python调用C++接口, 参数传递
int DllExport pke_decrypt(char *input1,char *input2,char* &vout) { std::string in1(input1); std::string in2(input2); std::string out = in1 + in2;...原创 2021-07-05 14:03:49 · 919 阅读 · 0 评论 -
Python调用C++接口,并支持callback
1. C++代码#include <stdio.h>extern "C"{int Print(const char *msg){printf("%s\n", msg);return 0;}int Add(int a, int b){return a + b;} struct Vector { int x; ...原创 2019-12-30 19:04:42 · 877 阅读 · 0 评论