General Blockproc questions that aren't in the documentation
이전 댓글 표시
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
채택된 답변
추가 답변 (2개)
Image Analyst
2026년 1월 22일
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
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
2026년 1월 25일
Jason
2026년 1월 22일
0 개 추천
댓글 수: 8
"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
2026년 1월 22일
Walter Roberson
2026년 1월 22일
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
2026년 1월 23일
Walter Roberson
2026년 1월 23일
I would need to see the code for blockProcInMemory
Jason
2026년 1월 23일
Walter Roberson
2026년 1월 23일
I guess I would need fun
카테고리
도움말 센터 및 File Exchange에서 Image Arithmetic에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



