Created
July 9, 2020 08:38
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
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
hi, how did you plot the pixellated image?