Skip to content

Instantly share code, notes, and snippets.

View zbrasseaux's full-sized avatar

Zachary P. Brasseaux zbrasseaux

View GitHub Profile
# code for https://www.reddit.com/r/ProgrammerHumor/comments/gawu9i/and_using_light_theme/fp2rtxa/
def function(num1, sign, num2):
if num1 == 1 and sign == '*' and num2 == 1:
print('1*1=1')
if num1 == 1 and sign == '*' and num2 == 2:
print('1*2=2')
if num1 == 1 and sign == '*' and num2 == 3:
print('1*3=3')
if num1 == 1 and sign == '*' and num2 == 4:
# code to generate code seen in https://i.redd.it/azecoqeevyv41.jpg
MAX = 12
print("\n\ndef function(num1, sign, num2):")
for i in range(MAX - 1):
for j in range(MAX - 1):
print("\tif num1 == " + str(i + 1) + " and sign == '*' and num2 == " + str(j + 1) + ":")
print("\t\tprint('" + str(i + 1) + "*" + str(j + 1) + "=" + str((i + 1)*(j + 1)) + "')")
function results = hw2_07
start_matrix = [4,4,4,4,8,8,8,8];
output_A = medfilt1(start_matrix, 3);
output_B = conv(start_matrix, [.25,.5,.25], 'same');
results = [start_matrix;output_A;output_B];
end
function end_matrix = hw2_06
% provided starting matrix
start_matrix = [0,-1,-2,-3,-4,-5,-6,-7;
1,0,-1,-2,-3,-4,-5,-6;
2,1,0,-1,-2,-3,-4,-5;
3,2,1,0,-1,-2,-3,-4;
4,3,2,1,0,-1,-2,-3;
5,4,3,2,1,0,-1,-2;
6,5,4,3,2,1,0,-1;
function [A,B] = hw2_05
% read in csv
matrix_input = csvread('hw2_05.csv');
% before histogram
A = histogram(matrix_input);
% provided filter
filter = [-1,2,-1];
% apply the filter to the image
matrix_input_post = conv2(matrix_input, filter, 'same');
% after histogram
import numpy as np
# define size of the output
SIZE_OF_ARRAY = 50
# start with an empty array
end_array = []
for i in range(0, SIZE_OF_ARRAY):
temp_arr = []
function [results] = hw2_04
% provided matrix and filters
image_x = [10,10,10,10,10,40,40,40,40,40];
filter_a = 1/5 * [1,1,1,1,1];
filter_b = 1/10 * [1,2,4,2,1];
% apply the filters to the image
results_a = conv2(image_x, filter_a, 'same');
results_b = conv2(image_x, filter_b, 'same');
function [x_filtered_std_dev] = hw2_03
% generate 10 images of size 256x256 of pixel value 128
x = ones(10,256,256)*128;
% apply gaussian noise
x = imnoise(x, 'gaussian', 0, 2.0);
% solution for homework problem 3
x_filtered = imgaussfilt(x, 1.4);
function [x_filtered_std_dev] = hw2_02
% generate 10 images of size 256x256 of pixel value 128
x = ones(10,256,256)*128;
% apply gaussian noise
x = imnoise(x, 'gaussian', 0, 2.0);
% solution for homework problem 2
x_filtered = apply_box_filter(x, 3);
function [x_std_dev] = hw2_01
% generate 10 images of size 256x256 of pixel value 128
x = ones(10,256,256)*128;
% apply gaussian noise
x = imnoise(x, 'gaussian', 0, 2.0);
% calculate standard deviation
x_std_dev = generate_std_dev(x);