MCPcopy Create free account
hub / github.com/geekcomputers/Python / main

Function main

Colors/pixel_sort.py:113–167  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

111
112
113def main():
114 global img_list
115 img = cv2.imread("Image/" + str(args.f) + ".jpg")
116 img = cv2.resize(img, (800, 500))
117 img_list.append(img)
118
119 height, width, _ = img.shape
120 print(">>> Row-wise Color sorting")
121 for row in tqdm(range(0, height)):
122 color, color_n = [], []
123 add = []
124
125 for col in range(0, width):
126 val = img[row][col].tolist()
127
128 # val includes all rgb values between the range of 0 to 1
129 # This makes the sorting easier and efficient
130 val = [i / 255.0 for i in val]
131 color.append(val)
132
133 thresh = findThreshold(
134 color, add
135 ) # setting the threshold value for every row in the frame
136
137 # For the specific row , if all the values are non-zero then it is sorted with color
138 if np.all(np.asarray(color)) == True:
139 color.sort(key=lambda bgr: step(bgr, 8)) # step sorting
140 band, img = generateColors(color, img, row)
141 measure(len(color), row, col, height, width)
142
143 # For the specific row , if any of the values are zero it gets sorted with color_n
144 if np.all(np.asarray(color)) == False:
145 for ind, i in enumerate(color):
146 # Accessing every list within color
147 # Added to color_n if any of the element in the list is non-zero
148 # and their sum is less than threshold value
149
150 if np.any(np.asarray(i)) == True and sum(i) < thresh:
151 color_n.append(i)
152
153 color_n.sort(key=lambda bgr: step(bgr, 8)) # step sorting
154 band, img = generateColors(color_n, img, row)
155 measure(len(color_n), row, col, height, width)
156 cv2.imwrite("Image_sort/" + str(args.f) + "/" + str(row + 1) + ".jpg", img)
157
158 # Writing down the final sorted image
159 cv2.imwrite(
160 "Image_sort/" + str(args.f) + "/" + str(args.f) + ".jpg", img
161 ) # Displaying the final picture
162
163 print("\n>>> Formation of the Video progress of the pixel-sorted image")
164 makeVideo()
165 sound.main(
166 args.f
167 ) # Calling the external python file to create the audio of the pixel-sorted image
168
169
170main()

Callers 1

pixel_sort.pyFile · 0.70

Calls 7

findThresholdFunction · 0.85
generateColorsFunction · 0.85
measureFunction · 0.85
makeVideoFunction · 0.85
stepFunction · 0.70
appendMethod · 0.45
mainMethod · 0.45

Tested by

no test coverage detected