def load_image_file(filename): try: raw_DicomData = pydicom.dcmread(filename) # pat_name = raw_DicomData.PatientName # display_name = pat_name.family_name + ", " + pat_name.given_name # Patient_Name = display_name # Patient_ID = raw_DicomData.PatientID # Modality = raw_DicomData.Modality # Study_Date = raw_DicomData.StudyDate DicomData = raw_DicomData.pixel_array # imageArr = convert_color_space(DicomData, 'YBR_FULL', 'RGB') image_pil = Image.fromarray(DicomData) except IOError: logger.error("Failed opening image file: {}".format(filename)) return # apply orientation to image according to exif image_pil = utils.apply_exif_orientation(image_pil) with io.BytesIO() as f: ext = osp.splitext(filename)[1].lower() if PY2 and QT4: format = "PNG" elif ext in [".jpg", ".jpeg"]: format = "JPEG" else: format = "PNG" image_pil.save(f, format=format) f.seek(0) return f.read()
def load_image_file(filename): raw_data = None ext = osp.splitext(filename)[1].lower() if ext == '.dcm': image_pil, raw_data = LabelFile.dcm2pil_image(filename) else: try: image_pil = PIL.Image.open(filename) except IOError: logger.error('Failed opening image file: {}'.format(filename)) return # apply orientation to image according to exif image_pil = utils.apply_exif_orientation(image_pil) with io.BytesIO() as f: ext = osp.splitext(filename)[1].lower() if PY2 and QT4: format = 'PNG' elif ext in ['.jpg', '.jpeg']: format = 'JPEG' else: format = 'PNG' image_pil.save(f, format=format) f.seek(0) return f.read(), raw_data
def load_image_file(filename): if osp.splitext(filename)[1] == ".dcm": if osp.exists(filename.replace(".dcm", ".jpg")): filename = filename.replace(".dcm", ".jpg") else: if os.name == 'posix': subprocess.call(["./script.sh", filename]) elif os.name == 'nt': subprocess.call(["script.bat", filename], **subprocess_args()) filename = filename.replace(".dcm", ".jpg") try: image_pil = PIL.Image.open(filename) except IOError: logger.error("Failed opening image file: {}".format(filename)) return # apply orientation to image according to exif image_pil = utils.apply_exif_orientation(image_pil) with io.BytesIO() as f: ext = osp.splitext(filename)[1].lower() if PY2 and QT4: format = "PNG" elif ext in [".jpg", ".jpeg"]: format = "JPEG" else: format = "PNG" image_pil.save(f, format=format) f.seek(0) return f.read()
def load_image_file(filename): try: image_pil = PIL.Image.open(filename) except IOError: logger.error("Failed opening image file: {}".format(filename)) return # apply orientation to image according to exif image_pil = utils.apply_exif_orientation(image_pil) with io.BytesIO() as f: ext = osp.splitext(filename)[1].lower() if PY2 and QT4: format = "PNG" elif ext in [".jpg", ".jpeg"]: format = "JPEG" else: format = "PNG" image_pil.save(f, format=format) f.seek(0) return f.read()
def load_image_file(filename): try: image_pil = PIL.Image.open(filename) except IOError: logger.error('Failed opening image file: {}'.format(filename)) return # apply orientation to image according to exif image_pil = utils.apply_exif_orientation(image_pil) with io.BytesIO() as f: ext = osp.splitext( filename)[1].lower() # 分离文件名和扩展名的元祖,ext为扩展名的小写(带.) if PY2 and QT4: format = 'PNG' elif ext in ['.jpg', '.jpeg']: format = 'JPEG' else: format = 'PNG' image_pil.save(f, format=format) f.seek(0) return f.read()
def load_image_file(filename): try: image_pil = PIL.Image.open(filename) # here at this place, I get the output image in the windows image_pil, corp_img_bbox = my_crop(filename) except IOError: logger.error('Failed opening image file: {}'.format(filename)) return # apply orientation to image according to exif image_pil = utils.apply_exif_orientation(image_pil) with io.BytesIO() as f: ext = osp.splitext(filename)[1].lower() if PY2 and QT4: format = 'PNG' elif ext in ['.jpg', '.jpeg']: format = 'JPEG' else: format = 'PNG' image_pil.save(f, format=format) f.seek(0) return f.read()