-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPydicom-Segmentation-PythonCode
More file actions
40 lines (40 loc) · 1.59 KB
/
Copy pathPydicom-Segmentation-PythonCode
File metadata and controls
40 lines (40 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from skimage import io
import matplotlib.pyplot as plt
import pydicom
import difflib
import numpy as np
import skimage.data as data
import skimage.segmentation as seg
import skimage.filters as filters
import skimage.draw as draw
import skimage.color as color
filename = 'CAP_SCD0000101_MR__hrt_raw_20120813120609855_17.dcm'
dx = pydicom.dcmread(filename)
def circle_points(resolution, center, radius):
#Generate points which define a circle on an image.Centre refers to the cent
radians = np.linspace(0, 2*np.pi, resolution)
c = center[1] + radius*np.cos(radians)#polar co-ordinates
r = center[0] + radius*np.sin(radians)
return np.array([c, r]).T
# Exclude last point because a closed path should not have duplicate points
points = circle_points(290, [130, 132], 40)[:-2]
def image_show(image, nrows=1, ncols=1, cmap='gray'):
fig, ax = plt.subplots(nrows=nrows, ncols=ncols, figsize=(14, 14))
ax.imshow(image, cmap='gray')
ax.axis('off')
return fig, ax
#plt.imshow(dx.pixel_array, cmap="gray")
image1 = io.imread('CAP_SCD0000101_MR__hrt_raw_20120813120609855_17.dcm')
#plt.imshow(image1);
image_gray = (image1) #color.rgb2gray(image1)
snake = seg.active_contour(image_gray, points,alpha=0.06,beta=0.01)
fig, ax = image_show(image1)
ax.plot(points[:, 0], points[:, 1], '--r', lw=3)
ax.plot(snake[:, 0], snake[:, 1], '-b', lw=3);
#No me esta funcionando con Pydicom pero si con io(importing)
#image2=plt.imshow(dx.pixel_array, cmap="gray")
#fig, ax = image_show(image2)
#ax.plot(points[:, 0], points[:, 1], '--r', lw=3)
#Subplot side by side view
#f, axarr = plt.subplots(1,2)
#axarr[0].imshow(dx.pixel_array, cmap="gray")