Last active
August 29, 2015 14:20
-
-
Save rainyear/ae1fa7e2b7ca9123c7f0 to your computer and use it in GitHub Desktop.
processing all jpg images from path <src> , crop <x> pixels from bottom, save to <dest>.
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 cropBottomByX(src, dest, x) | |
srcImgs = [dir([src filesep '*.jpg'])]; | |
for i = 1:length(srcImgs) | |
imgLocation = [src filesep srcImgs(i).name]; | |
img = imread(imgLocation); | |
[h, w, d] = size(img); | |
disp(sprintf('Resizing image %s from %d to %d ...\n', srcImgs(i).name, h, h-x)); | |
img2 = img(1:h-x, :, :); | |
imwrite(img2, [dest filesep srcImgs(i).name]); | |
end | |
end |
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 scaleToSizeXY(src, dest, width, height) | |
srcImgs = [dir([src filesep '*.jpg'])]; | |
for i = 1:length(srcImgs) | |
imgLocation = [src filesep srcImgs(i).name]; | |
img = imread(imgLocation); | |
[h, w, d] = size(img); | |
if h / w > height / width | |
h2 = floor(height / width * w); | |
img2 = img(floor((h - h2)/2):floor((h - h2)/2+h2), :, :); | |
elseif h / w <= height / width | |
w2 = floor(h * width / height); | |
img2 = img(:, floor((w-w2)/2):floor((w-w2)/2+w2),:); | |
end | |
disp(sprintf('Scale image %s...\n', srcImgs(i).name)); | |
img3 = imresize(img2, height / h); | |
imwrite(img3, [dest filesep srcImgs(i).name]); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment