General Blockproc questions that aren't in the documentation
Show older comments
I have 4 question's regarding Blockproc.
1: When you take an image and break it up into smaller images (ROI's) to use blockproc, what is the exact order of the smaller images
In my image below, the yellow box is "top-left"

Q2: Also, is there away to show grid lines like above just to verify where blockproc has operated?
Q3: Is it possible to use blockproc and NOT operate on all the smaller images, i.e. just the images where the cyan circles are?
Q4: Can you combine functions so blockproc doesn't have to run twice, e.g.:
fun = @(block_struct) mean2(block_struct.data);
AVG = blockproc(IM2,[500 500],fun,'UseParallel',true);
fun2 = @(block_struct) std2(block_struct.data);
SD = blockproc(IM2,[500 500],fun2,'UseParallel',true)
Thanks
Jason
Accepted Answer
More Answers (2)
Image Analyst
on 22 Jan 2026
You can use xline and yline in a for loop to overlay your red lines over the image. blockproc will not do that for you.
To do just certain block columns I'd probably just extract those columns into a new image and then process the whole image
threeColumns = grayImage(:, [col1:col2, col3:col4, col5:col6]);
though you can have blockproc "jump" or "overlap" blocks. See attached demos particularly the one that overlaps. Set the overlap to be positive instead of negative or vice versa so it jumps ahead rather than overlaps. I think you'll need two jump values, one for the rows of 0 and one for the columns of almost half the image width.
If you still need help, say so.
3 Comments
Start with row 1 and column 1
grayImage = imread('moon.tif');
imshow(grayImage);
[rows, columns] = size(grayImage)
stepWidth = 20;
for row = 1 : stepWidth : rows
yline(row, 'Color', 'r');
end
for col = 1 : stepWidth : columns
xline(col, 'Color', 'r');
end
Jason
on 25 Jan 2026
Jason
on 22 Jan 2026
0 votes
8 Comments
"Is it also possible to "exclude" and sub images that aren't full size (i,e where the red crosses are)"
All blocks are processed ,but there is nothing stopping you from returning some kind of magic number which has a special meaning.
I = imread('cameraman.tif');
bs = [71,71];
% Just to show the block sizes on the image:
J = blockproc(I, bs, @(s) addBorderGray(s,128));
imshow(J);
For example, lets get the mean of all full-sized blocks and return NaN for all smaller blocks:
K = blockproc(I, bs, @(s) getMean(s,bs))
And, exactly as I wrote in my answer, you can check anything in that conditional: size, color, etc.
function out = getMean(s,bs)
if isequal(s.blockSize,bs)
out = mean2(s.data);
else
out = NaN;
end
end
function out = addBorderGray(s, val)
out = s.data;
out(1,:) = val; % top
out(end,:) = val; % bottom
out(:,1) = val; % left
out(:,end) = val; % right
end
Jason
on 22 Jan 2026
Walter Roberson
on 22 Jan 2026
If you use PadPartialBlocks together with 'PadMethod', nan then taking the mean or std of a padded partial block will return nan (because mean or std of data that includes nan, results in nan). In that way you would not need special code to check the size.
Jason
on 23 Jan 2026
Walter Roberson
on 23 Jan 2026
I would need to see the code for blockProcInMemory
Jason
on 23 Jan 2026
Walter Roberson
on 23 Jan 2026
I guess I would need fun
Categories
Find more on Blocked Images in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


