def pixel_sort_brighter_than_rgb(X, r, g, b, strict=False, sorting_order=('h', 'l', 'v'), iterations=8):
"""begin sorting when it finds a pixel which is not (r,g,b) in the column or row,
and will stop sorting when it finds a (r,g,b) pixel"""
I = X.copy()
for row in prange(0, pgc.height(I)):
if strict:
from_idx = np.argwhere((I[row, :-1, pgc.CH_RED] > r) & (I[row, :-1, pgc.CH_GREEN] > g)
& (I[row, :-1, pgc.CH_BLUE] > b))
else:
from_idx = np.argwhere((I[row, :-1, pgc.CH_RED] > r) | (I[row, :-1, pgc.CH_GREEN] > g)
| (I[row, :-1, pgc.CH_BLUE] > b))
to_idx = np.argwhere((I[row, :-1, pgc.CH_RED] <= r) & (I[row, :-1, pgc.CH_GREEN] <= g)
& (I[row, :-1, pgc.CH_BLUE] <= b))
if from_idx.size > 0 and to_idx.size > 0:
i = from_idx[0][0]
matches = np.argwhere(to_idx > i)
while not matches.size == 0:
j = to_idx[matches[0][0]][0]
I_hlv = __rgb2hlv(I[row, i:j, 0:3], iterations)
sort_idx = np.argsort(I_hlv, order=sorting_order)
I[row, i:j] = I[row, i+sort_idx]
matches_i = np.argwhere(from_idx > j)
if matches_i.size == 0:
break
else:
i = from_idx[matches_i[0][0]][0]
matches = np.argwhere(to_idx > i)
return I
评论列表
文章目录