Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions app/services/filters/median_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,34 @@ def filtred(img=false)
end

def get_midle(x,y, img)
arr = []
rez = {}
arr_r = []
arr_g = []
arr_b = []

3.times do |x_off|
3.times do |y_off|
begin
arr << img[x+1-x_off,y+1-y_off]
pixel = to_rgb(img[x+1-x_off,y+1-y_off])
arr_r << (pixel[:R])
arr_g << (pixel[:G])
arr_b << (pixel[:B])
rescue
arr << 0
arr_r << 0
arr_g << 0
arr_b << 0
end
end
end
arr.sort[4]

ChunkyPNG::Color.rgb(arr_r.sort[4], arr_g.sort[4], arr_b.sort[4])
end

def to_rgb(pixel)
arr = {}
arr[:R] = ChunkyPNG::Color.r(pixel)
arr[:G] = ChunkyPNG::Color.g(pixel)
arr[:B] = ChunkyPNG::Color.b(pixel)
arr
end
end