Last active
August 29, 2015 14:08
-
-
Save brogand93/51217ec380e9bc383291 to your computer and use it in GitHub Desktop.
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
% Creates a mask from given inputs | |
% Author Darren Brogan | |
% Heavily derived from createMask2 by Dan Malone | |
% Diff @ https://gist.github.com/BroganD1993/51217ec380e9bc383291/revisions | |
function image_mask = create_mask(image_mask, fft, num_shapes) | |
image_mask = generate_user_shapes(image_mask, fft, num_shapes); | |
image_mask = flip_mask_and_combine(image_mask); | |
image(256*image_mask); | |
end | |
function image_mask = generate_user_shapes(image_mask, fft, num_shapes) | |
[size_y, size_x] = size(fft); | |
for current_shape = 0:(num_shapes - 1), | |
image_mask = flip_mask_and_combine(image_mask); | |
image(256 * (image_mask + log(abs(fft)) / max(max(log(abs(fft)))))); | |
colormap(gray(256)); | |
[x, y] = read_points_and_repair(size_x, size_y); | |
image_mask = plot_user_mask(image_mask, x, y); | |
end | |
end | |
function [x, y] = read_points_and_repair(size_x, size_y) | |
[x, y] = ginput(2); | |
[x, y] = reorient_coordinates(x, y); | |
[x, y] = handle_bounds_errors_on_coordinates(x, y, size_x, size_y); | |
disp('The input co-ordinates are: '); | |
disp([x, y]); | |
end | |
function [x, y] = reorient_coordinates(x, y) | |
x = reorient_coordinate(x); | |
y = reorient_coordinate(y); | |
end | |
function coordinate = reorient_coordinate(coordinate) | |
if(coordinate(2) < coordinate(1)) | |
coordinate = switch_coordinates(coordinate); | |
end | |
end | |
function coordinates = switch_coordinates(coordinates) | |
temp_coordinate = coordinates(1); | |
coordinates(1) = coordinates(2); | |
coordinates(2) = temp_coordinate; | |
end | |
function [x, y] = handle_bounds_errors_on_coordinates(x, y, size_x, size_y) | |
x = max(x, 1); | |
y = max(y, 1); | |
x = min(x, size_x); | |
y = min(y, size_y); | |
x = round(x); | |
y = round(y); | |
end | |
function image_mask = plot_user_mask(image_mask, x, y) | |
image_mask((y(1)):(y(2)), (x(1)):(x(2))) = 1; | |
end | |
function image_mask = flip_mask_and_combine(image_mask) | |
flipped_mask = flip_mask(image_mask); | |
image_mask = combine_masks(image_mask, flipped_mask); | |
end | |
function mirrored_mask = flip_mask(image_mask) | |
mirrored_mask = rot90(image_mask, 2); | |
end | |
function combined_masks = combine_masks(image_mask, mirrored_mask) | |
combined_masks = bitor(image_mask, mirrored_mask); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment