2016-07-11 4 views
1

주어진 이미지에 대해 32x32 픽셀의 패치를 만드는 기능이 있습니다. 모든 패치가 포함 된 셀을 반환합니다. 이미지 형식이 350 * 350 * 3 인 경우 이미지 형식이 256 * 150 인 경우 빈 이미지가 포함 된 셀을 반환하지만 제대로 작동합니다. 재밌는 것은 내가 셀 내부의 패치를 생성하는 코드를 디버깅 할 수 있지만 셀 내부에 패치를 반환하면 셀이 비게됩니다. setimage 코드를 사용하여 이러한 이미지를 저장하려고합니다. 아무도 이걸 도와 드릴까요? 블록의 mean2의 valuee를 확인하는 동안matlab을 사용하여 Deeplearning을위한 패치 만들기

% Demo to divide a color image up into blocks. 
function [imageSet] = CreatePatches(imag) 
fontSize = 20; 
%rgbImage = imread(imag); 
rgbImage =imag; 
% imshow(rgbImage); 
% Enlarge figure to full screen. 
set(gcf, 'units','normalized','outerposition',[0 0 1 1]); 
% drawnow; 
% Get the dimensions of the image. numberOfColorBands should be = 3. 
[rows columns numberOfColorBands] = size(rgbImage) 
%========================================================================== 
% divide an image up into blocks is by using mat2cell(). 
blockSizeR = 32; % Rows in block. 
blockSizeC = 32; % Columns in block. 
% Figure out the size of each block in rows. 
% Most will be blockSizeR but there may be a remainder amount of less than that. 
wholeBlockRows = floor(rows/blockSizeR); 
blockVectorR = [blockSizeR * ones(1, wholeBlockRows), rem(rows, blockSizeR)]; 
% Figure out the size of each block in columns. 
wholeBlockCols = floor(columns/blockSizeC); 
blockVectorC = [blockSizeC * ones(1, wholeBlockCols), rem(columns, blockSizeC)]; 
% Create the cell array, ca. 
% Each cell (except for the remainder cells at the end of the image) 
% in the array contains a blockSizeR by blockSizeC by 3 color array. 
% This line is where the image is actually divided up into blocks. 
if numberOfColorBands > 1 
    % It's a color image. 
    ca = mat2cell(rgbImage, blockVectorR, blockVectorC, numberOfColorBands); 

else 
    ca = mat2cell(rgbImage, blockVectorR, blockVectorC); 
end 
% Now display all the blocks. 
plotIndex = 1; 
numPlotsR = size(ca, 1); 
numPlotsC = size(ca, 2); 

for r = 1 : numPlotsR 
    for c = 1 : numPlotsC 
%  fprintf('plotindex = %d, c=%d, r=%d\n', plotIndex, c, r); 
     % Specify the location for display of the image. 
%  subplot(numPlotsR, numPlotsC, plotIndex); 
     % Extract the numerical array out of the cell 
     % just for tutorial purposes. 

     rgbBlock = ca{r,c}; 
     if mean2(rgbBlock) < 15 % Or whatever value you want 
      continue; 
     end 
%  imshow(rgbBlock); % Could call imshow(ca{r,c}) if you wanted to. 
     [rowsB columnsB numberOfColorBandsB] = size(rgbBlock); 
     %imwrite(ca{r,c},['image',num2str(plotIndex),'.jpeg']); 
     % Make the caption the block number. 
%   caption = sprintf('Block #%d of %d\n%d rows by %d columns', ... 
%  plotIndex, numPlotsR*numPlotsC, rowsB, columnsB); 
%  title(caption); 
%  drawnow; 
     % Increment the subplot to the next location. 
     plotIndex = plotIndex + 1; 
     imageSet ={}; 
     for x =1: plotIndex 
      %imshow(rgbBlock); 
      imageSet{end+1} = rgbBlock; 
     end 
    end 


end 

답변

1

그냥 다음 라인을 추가하십시오 Imageset에 문제를 설명하지만, 의미가 내 문제를 해결하지 않는

if mean2(rgbBlock) < 15|isempty(rgbBlock) == 1 
+0

감사합니다. – Mensch

관련 문제