DebasishDhal99 commited on
Commit
1c552db
·
1 Parent(s): 7c4249a

Update channel_functions.py

Browse files
Files changed (1) hide show
  1. channel_functions.py +11 -7
channel_functions.py CHANGED
@@ -7,7 +7,7 @@ def individual_channel_image(img_arr, channel= 'r', ax=None):
7
  img_arr = img_arr[:,:,0:3]
8
 
9
  if channel in ['r','red','Red']:
10
- plot_arr = img_arr[:,:,2]
11
  channel_name = 'Red'
12
  cmap = 'Reds'
13
  if channel in ['g','green','Green']:
@@ -15,7 +15,7 @@ def individual_channel_image(img_arr, channel= 'r', ax=None):
15
  channel_name = 'Green'
16
  cmap = 'Greens'
17
  if channel in ['b','blue','Blue']:
18
- plot_arr = img_arr[:,:,0]
19
  channel_name = 'Blue'
20
  cmap = 'Blues'
21
 
@@ -48,8 +48,10 @@ def channel_distribution_plotter(img_array):
48
 
49
  img_array = img_array[:,:,:3] #Not considering the A channel, if it's a RGBA image.
50
 
 
 
51
  plt.subplot(2,2,1)
52
- plt.hist(img_array[:,:,2].ravel(),bins=256,color='red');
53
  plt.title("Red Channel")
54
 
55
  plt.subplot(2,2,2)
@@ -57,7 +59,7 @@ def channel_distribution_plotter(img_array):
57
  plt.title("Green Channel")
58
 
59
  plt.subplot(2,2,3)
60
- plt.hist(img_array[:,:,1].ravel(),bins=256,color='blue');
61
  plt.title("Blue Channel")
62
 
63
  plt.subplot(2,2,4)
@@ -66,10 +68,12 @@ def channel_distribution_plotter(img_array):
66
 
67
  plt.suptitle("Pixel values distribution in each channel\nx-axis: pixel values, y-axis: number of pixels")
68
  plt.tight_layout()
69
-
70
  plt.show()
71
-
72
-
 
 
73
 
74
 
75
  def which_channel_dominates(img_arr, original_image_plot = 'yes', original_image_opacity = 0.3, channel_opacity = 0.7):
 
7
  img_arr = img_arr[:,:,0:3]
8
 
9
  if channel in ['r','red','Red']:
10
+ plot_arr = img_arr[:,:,0]
11
  channel_name = 'Red'
12
  cmap = 'Reds'
13
  if channel in ['g','green','Green']:
 
15
  channel_name = 'Green'
16
  cmap = 'Greens'
17
  if channel in ['b','blue','Blue']:
18
+ plot_arr = img_arr[:,:,2]
19
  channel_name = 'Blue'
20
  cmap = 'Blues'
21
 
 
48
 
49
  img_array = img_array[:,:,:3] #Not considering the A channel, if it's a RGBA image.
50
 
51
+ fig, ax = plt.subplots(figsize=(8,8))
52
+
53
  plt.subplot(2,2,1)
54
+ plt.hist(img_array[:,:,0].ravel(),bins=256,color='red');
55
  plt.title("Red Channel")
56
 
57
  plt.subplot(2,2,2)
 
59
  plt.title("Green Channel")
60
 
61
  plt.subplot(2,2,3)
62
+ plt.hist(img_array[:,:,2].ravel(),bins=256,color='blue');
63
  plt.title("Blue Channel")
64
 
65
  plt.subplot(2,2,4)
 
68
 
69
  plt.suptitle("Pixel values distribution in each channel\nx-axis: pixel values, y-axis: number of pixels")
70
  plt.tight_layout()
71
+
72
  plt.show()
73
+ fig.canvas.draw()
74
+ image_array = np.array(fig.canvas.renderer.buffer_rgba())
75
+ return image_array
76
+
77
 
78
 
79
  def which_channel_dominates(img_arr, original_image_plot = 'yes', original_image_opacity = 0.3, channel_opacity = 0.7):