Is there a substitute for blockproc in Matlab?

后端 未结 2 1739
借酒劲吻你
借酒劲吻你 2020-11-29 11:42

I\'ve been using blockproc for processing images blockwise. Unfortunately, blockproc is part of the Image Processing Toolbox, which I don\'t have on my personal

相关标签:
2条回答
  • 2020-11-29 12:12

    Here is an example using MAT2CELL. It dividing the image into N-by-M tiles, and handles the case when the image size is not evenly divisible by the number of tiles.

    %# 2D grayscale image
    I = imread('coins.png');
    
    %# desird number of horizontal/vertical tiles to divide the image into
    numBlkH = 4;
    numBlkW = 4;
    
    %# compute size of each tile in pixels
    [imgH,imgW,~] = size(I);
    szBlkH = [repmat(fix(imgH/numBlkH),1,numBlkH-1) imgH-fix(imgH/numBlkH)*(numBlkH-1)];
    szBlkW = [repmat(fix(imgW/numBlkW),1,numBlkW-1) imgW-fix(imgW/numBlkW)*(numBlkW-1)];
    
    %# divide into tiles, and linearize using a row-major order
    C = mat2cell(I, szBlkH, szBlkW)';
    C = C(:);
    
    %# display tiles i subplots
    figure, imshow(I)
    figure
    for i=1:numBlkH*numBlkW
        subplot(numBlkH,numBlkW,i), imshow( C{i} )
    end
    

    The input image and the resulting tiles:

    input_image tiles

    0 讨论(0)
  • 2020-11-29 12:24

    Won't mat2tiles together with cellfun and cell2mat do more or less what blockproc does?

    You could write a wrapper yourself to make it use the same arguments as blockproc, I don't think it should be that hard to do.

    0 讨论(0)
提交回复
热议问题