Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [newImg] = myMedian(srcimg, rows, cols)
- %TODO - pad the image
- imageWidth = size(srcimg, 1);
- imageHeight = size(srcimg, 2);
- disp(imageHeight);
- disp(imageWidth);
- pad = max(floor(rows / 2), floor(cols / 2));
- paddedmat = zeros(size(srcimg) + pad);
- for x=pad + 1:size(srcimg,1)
- for y=pad + 1:size(srcimg,2)
- paddedmat(x,y)=srcimg(x - pad + 1, y - pad + 1);
- end
- end
- srcimg = paddedmat;
- outputimg = zeros(size(srcimg));
- outputimg = double(outputimg);
- windowHeight = rows;
- windowWidth = cols;
- window = zeros(1, windowHeight * windowWidth);
- edgex = floor(windowHeight / 2);
- edgey = floor(windowWidth / 2);
- helperHeight = floor((windowHeight / 2));
- helperWidth = floor((windowHeight / 2));
- for x = edgex + 1:(size(srcimg, 1) - pad)
- for y = edgey + 1:(size(srcimg, 2) - pad)
- %disp("x: " + x + ", y: " + y);
- %disp("edgex: " + edgex);
- %disp("edgey: " + edgey);
- %disp("pad: " + pad);
- k = srcimg(x - helperHeight:x + helperHeight, y - helperWidth:y + helperWidth);
- window = reshape(k,1,[]);
- window = sort(window);
- outputimg(x, y) = window( floor((windowWidth * windowHeight) / 2));
- end
- end
- %disp(pad);
- newImg = outputimg(1 + pad:size(outputimg, 1),1 + pad:size(outputimg, 2));%zeros(0);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement