Eliminate color transition effects at the edge of two colors in an image

I cannot remember in my life the name of this operation. The operation is determined so that the pixel in question is replaced by the pixel value of the highest frequency in the kernel window.

The goal is to eliminate extraneous colors that can be found at the edges of other more visible areas and combine with a smaller subset of colors.

For example, consider the Congo flag:

enter image description here

If we approach the border between the two colors, we observe the effect of a color transition.

enter image description here

For my purposes, there are only two colors in the above image, but the diagonal shape lends itself to a combination of boundary colors.

+4
source share
1

, ( ) .

MATLAB, , colfilt, .

output = colfilt(data, [5 5], 'sliding', @mode)

, padarray, 3 , , 3 .

% Pad with replicates of the data
data = padarray(data, [3 3], 'replicate', 'both');

% Perform the filtering
new = colfilt(data, [5 5], 'sliding', @mode);

% Crop out the padding part
new = new(4:end-3,4:end-3);

​​ n, :

function out = mode_filter(data, n)

    pad_size = ceil(n / 2);

    % Pad with replicates of the data
    data = padarray(data, [pad_size, pad_size], 'replicate', 'both');

    % Perform the filtering
    out = colfilt(data, [n n], 'sliding', @mode);

    % Crop out the padded part
    out = out((pad_size + 1):(end - pad_size), (pad_size + 1):(end - pad_size));
end
+6

Source: https://habr.com/ru/post/1657564/


All Articles