مثال: پردازش یک دنباله از تصاویر-۱
مثال: پردازش یک دنباله از تصاویر
در این مثال، یک سری از تصاویر از یک دایرکتوری خاص خوانده شده و به درون فضای کاری متلب منتقل می شوند. در این مثال، تصاویر به صورت یک آرایه سه بعدی m×n×p خوانده و در فضای کاری متلب ذخیره می شوند. سپس تابع stdfilt روی همه تصاویر اعمال می شود. این تابع کار فیلتر کردن مبتنی بر انحراف معیار را روی تک تک تصاویر انجام م یدهد. با توجه به توضیحات جدول اخیر در مورد تابع stdfilt ملاحظه میکنید که باید از آرگومان nhood استفاده کنیم. بنابراین، ابتدا از تابع stdfilt راهنما بگیرید:
>> help stdfilt
STDFILT Local standard deviation of image.
J = STDFILT(I) returns the array J, where each output pixel contains the
standard deviation value of the 3‐by‐3 neighborhood around the corresponding
pixel in the input image I. I can have any dimension. The output image J is
the same size as the input image I.
For pixels on the borders of I, STDFILT uses symmetric padding. In
symmetric padding, the values of padding pixels are a mirror reflection
of the border pixels in I.
J = STDFILT(I,NHOOD) performs standard deviation filtering of the input
image I where you specify the neighborhood in NHOOD. NHOOD is a
multidimensional array of zeros and ones where the nonzero elements specify
the neighbors. NHOOD’s size must be odd in each dimension.
By default, STDFILT uses the neighborhood ones(3). STDFILT determines the
center element of the neighborhood by FLOOR((SIZE(NHOOD) + 1)/2). For
information about specifying neighborhoods, see Notes.
Class Support
‐‐‐‐‐‐‐‐‐‐‐‐‐
I can be logical or numeric and must be real and nonsparse. NHOOD can be
logical or numeric and must contain zeros and/or ones. I and NHOOD can have
any dimension. J is double.
Notes
‐‐‐‐‐
To specify the neighborhoods of various shapes, such as a disk, use the
STREL function to create a structuring element object and then use the
GETNHOOD function to extract the neighborhood from the structuring element
object.
Examples
‐‐‐‐‐‐‐‐
I = imread(‘circuit.tif’);
J = stdfilt(I);
imshow(I);
figure, imshow(J,[]);
See also std2, rangefilt, entropyfilt, strel, GETNHOOD.
ملاحظه می کنید که nhood تعیین کننده پیکسلهایی است که باید در کار محاسبه ی انحراف معیار محلی برای این آرگومان از آنها استفاده کنیم. در مثال فعلی، از (ones(3 استفاده شده است. یعنی یک همسایگی دو بعدی تعریف شده است.
برنامه ی مثال:
% Create an array of filenames that make up the image sequence
fileFolder = fullfile(matlabroot,’toolbox’,’images’,’imdemos’);
dirOutput = dir(fullfile(fileFolder,’AT3_1m4_*.tif’));
fileNames = {dirOutput.name}’;
numFrames = numel(fileNames);
I = imread(fileNames{1});
% Preallocate the array
sequence = zeros([size(I) numFrames],class(I));
sequence(:,:,1) = I;
% Create image sequence array
for p = 2:numFrames
sequence(:,:,p) = imread(fileNames{p});
end