import pandas as pd
import SimpleITK as sitk
import os
import pydicom
import numpy as np
import matplotlib.pyplot as plt
import nrrd
import matplotlib.image as mpimg
from PIL import Image
import glob
import cv2
import pickle
jpg_seg_read_path = "/Users/yxk/Desktop/核磁项目/ALL_sample/seg_pic/安芮716608_000007_seg.jpg"
seg_image = Image.open(jpg_seg_read_path)
seg_img_arr = np.array(seg_image)
print(seg_img_arr.shape)
print(np.sum(seg_img_arr[:,:,0] != seg_img_arr[:,:,2]))
print(np.sum(seg_img_arr[:,:,0] != seg_img_arr[:,:,1]))
print(np.sum(seg_img_arr[:,:,1] != seg_img_arr[:,:,2]))
plt.imshow(seg_img_arr,cmap='gray')
# seg_img_arr
给三维的图片添加分割线
seg_img_arr[100:300,200,:]=[255,0,0] # 垂直线:x=200
seg_img_arr[100:300,300,:]=[0,255,0] # 垂直线:x=300
seg_img_arr[100,200:300,:]=[0,0,255] # 垂直线:x=300
seg_img_arr[300,200:300,:]=[0,0,255] # 垂直线:x=300
plt.imshow(seg_img_arr,cmap='gray')
# img_arr[mask_pos[:,:,0],:] = [255,0,0] ## 注意numpy array是可以一次性赋值的,不需要一个个赋值
# pil_img = Image.fromarray(img_arr)
# #dcm_id,_ = file.split(".")
# pil_img.save(save_mask_dir+ patient + str(id) + "_" +'{0:06d}'.format(i)+ "_mask.jpg")
example
import pandas as pd
import SimpleITK as sitk
import os
import pydicom
import numpy as np
import matplotlib.pyplot as plt
import nrrd
import matplotlib.image as mpimg
from PIL import Image
import glob
import cv2
import pickle
jpg_seg_read_path = "/Users/yxk/Desktop/核磁项目/ALL_sample/seg_pic/安芮716608_000008_seg.jpg"
seg_image = Image.open(jpg_seg_read_path)
seg_img_arr = np.array(seg_image)
print(seg_img_arr.shape)
print(np.sum(seg_img_arr[:,:,0] != seg_img_arr[:,:,2]))
print(np.sum(seg_img_arr[:,:,0] != seg_img_arr[:,:,1]))
print(np.sum(seg_img_arr[:,:,1] != seg_img_arr[:,:,2]))
plt.imshow(seg_img_arr,cmap='gray')
# seg_img_arr
img_arr = seg_img_arr[:,:,0]
print(img_arr.shape)
nonzero_pos = np.argwhere(img_arr > 0)
#####
left_value=min(nonzero_pos[:,1])
right_value=max(nonzero_pos[:,1])
upper_value = min(nonzero_pos[:,0])
lower_value= max(nonzero_pos[:,0])
print("left_value ={}".format(left_value))
print("right_value={}".format(right_value))
print("upper_value={}".format(upper_value))
print("lower_value={}".format(lower_value))
seg_img_arr[upper_value:lower_value,left_value,:]=[255,0,0] # 垂直线:x=200
seg_img_arr[upper_value:lower_value,right_value,:]=[255,0,0]# 垂直线:x=300
seg_img_arr[upper_value,left_value:right_value,:]=[255,0,0]# 水平线:x=100
seg_img_arr[lower_value,left_value:right_value,:]=[255,0,0] # 水平线:x=300
# seg_img_arr[100:300,224,:]=[255,0,0] # 垂直线:x=200
# seg_img_arr[100:300,279,:]=[0,255,0] # 垂直线:x=300
# seg_img_arr[200,200:300,:]=[0,0,255] # 垂直线:x=300
# seg_img_arr[239,200:300,:]=[0,0,255] # 垂直线:x=300
# # plt.imshow(seg_img_arr,cmap='gray')
plt.imshow(seg_img_arr,cmap='gray')