Skip to content

Instantly share code, notes, and snippets.

@anishLearnsToCode
Created July 9, 2020 08:38
Show Gist options
  • Select an option

  • Save anishLearnsToCode/c998424d76e37167a7adb61b98cbd6f8 to your computer and use it in GitHub Desktop.

Select an option

Save anishLearnsToCode/c998424d76e37167a7adb61b98cbd6f8 to your computer and use it in GitHub Desktop.
This is a MATLAB function that pixelates a given image with parameter w. uses a 2w+1 mask size for blurring.
function W = pixelate(I, w)
[n, m, ~] = size(I);
W = I;
for row = w + 1 : 2 * w + 1 : n + w
for column = w + 1 : 2 * w + 1 : m + w
row_upper = upper(row + w, n, n);
column_upper = upper(column + w, m, m);
sub_image = I(row - w : row_upper, column - w : column_upper, :);
average = mean(mean(sub_image));
W(row - w : row_upper, column - w : column_upper, :) = average .* ...
ones(row_upper - row + w + 1, column_upper - column + w + 1, 3);
end
end
end
function value = upper(value, threshold, default)
if value > threshold
value = default;
end
end
@conaleccou
Copy link

hi, how did you plot the pixellated image?

@anishLearnsToCode
Copy link
Author

We can display any mage in matlab using the imshow() method. after calling this function simply pass in the returned image in imshow(R) where R is the result.

imshow(R);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment