%[x, imagerows, imagecols] = cut_evzr('1.jpg', 32, 32);

function [x, imagerows, imagecols] = cut_evzr(filename, w, h);

%clear all
%close all
%w=8;
%h=8;
%filename='smallpart33.jpg'

image = imread(filename);
figure; imshow(image)

YIQ = rgb2ntsc(image);
YIQ = double(image)./255; 
I = YIQ(:,:,1);
figure; imshow(I)

%define rows of the resulting x
newrows = 28

rows = size(image,1);
cols = size(image,2);

fprintf(1,'Size of the original image %d %d\n',rows, cols);

%modified code
marginh = mod (rows,h);
marginw = mod (cols,w);

I([rows-marginh+1:end],:) = [];
I(:,[cols-marginw+1:end]) = [];

x_temp = im2col(I,[h w],'distinct');

x_temp_rows = size(x_temp,1);
x_temp_cols = size(x_temp,2);

imagerows = size(I,1);
imagecols = size(I,2);

% y = zeros(newrows,x_temp_cols);
% 
% %copy 28 cells for each block
% for m = 1:1:x_temp_cols
%     k = 1;    
%     %take the first row
%     for n = 1:8:x_temp_rows
%         y(k,m) = x_temp(n,m);
%         k = k + 1;
%     end
%     %take the last col
%     for n = (n+1):1:x_temp_rows
%         y(k,m) = x_temp(n,m);
%         k = k + 1;
%     end
%     %take the last row
%     for n = (x_temp_rows - h):-8:h
%         y(k,m) = x_temp(n,m);
%         k = k + 1;
%     end
%     %take the first col    
%     for n = (h-1):-1:2
%         y(k,m) = x_temp(n,m);
%         k = k + 1;
%     end
% end

x = x_temp;

fprintf(1,'Whole image cut and stripped, size %d %d\n', size(x));
