how to make pixels to black if it is more or less than threshold

sir i have a image of size 320X640 and it has divided into blocks of size 32X64 ie totally i have 100 blocks and and number of black pixel in each block is stored in a matrix (10X10)
now i need to make EACH BLOCK black if number of black pixels in each block is more or less(><)than 211 how can it be done plz help me

1 Comment

That's a peculiar condition. How likely is it that the blocks of your image will have _exactly_ 211 black pixels ??

Sign in to comment.

 Accepted Answer

Call the below function with blkproc:
X = blkproc(I,[64 32],@Black211)
%%Save the below as Black211.m
function out = Black211(in)
%If there are not exactly 211 black pixels; make the whole thing black
is211black = sum(~in(:))==211;
if ~is211black
out = false(size(in));
else
out = in;
end

4 Comments

blkproc() is no longer documented in 2010b; blockproc() is its replacement.
The replacement version would not need to examine the data itself, as the original poster already has a matrix of pixel counts.
I'll bet (from his post earlier today) that he's generating that 10x10 with blkproc and then trying to use it as the criteria for replacing with zeros. It would be easiest to do it all in one shot.
Also, blockproc is much slower than blkproc as many CSSM threads have covered. For those of us not on 2010b, avoidance of blockproc is a good thing, especially when the additional features are not needed.
<http://www.mathworks.com/matlabcentral/newsreader/view_thread/282819#757314>
<http://www.mathworks.com/matlabcentral/newsreader/view_thread/288508#768820>
Or...you could use the improvements to BLOCKPROC as a compelling reason (one of many!) to update your MATLABs! :)
Brett, that could possibly require a walk through this New England downpour to a building about 500ft away. Are the blockproc improvements really that good?!?! ;)

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!