image processing - Creating patches for Deeplearning using matlab -
i have function creates patches of 32x32 pixels given image. returns cell contains patches. if image on format 350*350*3, works although if image of format 256*150 , returns cell empty images. funny thing if debug code create patches inside cell fine , when returning patches inside cell, cell becomes empty.i trying save such images using setimage code. ?
% demo divide color image blocks. function [imageset] = createpatches(imag) fontsize = 20; %rgbimage = imread(imag); rgbimage =imag; % imshow(rgbimage); % enlarge figure full screen. set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % drawnow; % dimensions of image. numberofcolorbands should = 3. [rows columns numberofcolorbands] = size(rgbimage) %========================================================================== % divide image blocks using mat2cell(). blocksizer = 32; % rows in block. blocksizec = 32; % columns in block. % figure out size of each block in rows. % blocksizer there may remainder amount of less that. wholeblockrows = floor(rows / blocksizer); blockvectorr = [blocksizer * ones(1, wholeblockrows), rem(rows, blocksizer)]; % figure out size of each block in columns. wholeblockcols = floor(columns / blocksizec); blockvectorc = [blocksizec * ones(1, wholeblockcols), rem(columns, blocksizec)]; % create cell array, ca. % each cell (except remainder cells @ end of image) % in array contains blocksizer blocksizec 3 color array. % line image divided blocks. if numberofcolorbands > 1 % it's color image. ca = mat2cell(rgbimage, blockvectorr, blockvectorc, numberofcolorbands); else ca = mat2cell(rgbimage, blockvectorr, blockvectorc); end % display blocks. plotindex = 1; numplotsr = size(ca, 1); numplotsc = size(ca, 2); r = 1 : numplotsr c = 1 : numplotsc % fprintf('plotindex = %d, c=%d, r=%d\n', plotindex, c, r); % specify location display of image. % subplot(numplotsr, numplotsc, plotindex); % extract numerical array out of cell % tutorial purposes. rgbblock = ca{r,c}; if mean2(rgbblock) < 15 % or whatever value want continue; end % imshow(rgbblock); % call imshow(ca{r,c}) if wanted to. [rowsb columnsb numberofcolorbandsb] = size(rgbblock); %imwrite(ca{r,c},['image',num2str(plotindex),'.jpeg']); % make caption block number. % caption = sprintf('block #%d of %d\n%d rows %d columns', ... % plotindex, numplotsr*numplotsc, rowsb, columnsb); % title(caption); % drawnow; % increment subplot next location. plotindex = plotindex + 1; imageset ={}; x =1: plotindex %imshow(rgbblock); imageset{end+1} = rgbblock; end end end
just add these line while checking mean2 valuee of block :
if mean2(rgbblock) < 15|isempty(rgbblock) == 1
Comments
Post a Comment