Image Processing Toolbox | ![]() ![]() |
Passing an M-File Function to a Function Function
Create an M-file containing your block-processing function. Using the example function above, your M-file might contain the following lines.
function y = myblkfun(x,P1) % For an input block of x, divide the pixel values by P1. % Temporarily make x double so you can perform arithmetic on it. y = uint8(double(x)*P1);
To use your M-file with blkproc
, create a function handle (function_handle
) to it, and pass in the handle and any desired value for P1
. For example,
I = imread('cameraman.tif'); f = @myblkfun; % Create a function handle. I2 = blkproc(I, [10 10], f, 2); imshow(I); figure, imshow(I2);
Figure A-1: Original Image (left) and Brightened Image (right)
![]() | Working with Function Functions | Passing an Inline Object to a Function Function | ![]() |