Speed up the code

조회 수: 3 (최근 30일)
Saurabh
Saurabh 2012년 2월 3일
편집: Mary Jon 2013년 10월 1일
I want to speed up the code(replace the for loop) for checking whether the pixel at the center of the 3x3 neighbourhood is a minima or not. Can anyone help me with that.
function [critical_map] = Make_Critical_Map(gray_image)
[rows cols] = size(gray_image);
critical_map = zeros(rows,cols);
for i = 1:rows
for j = 1:cols
test = true;
%Check whether the gray value is lowest in the 3x3 neighbourhood
for row_inc = -1:1
if(test == true)
for col_inc = -1:1
if(test == true)
if ((i+row_inc)>=1) && ((i+row_inc)<=rows) && ((j+col_inc)>=1) && ((j+col_inc)<=cols) && (gray_image(i+row_inc,j+col_inc)<gray_image(i,j))
test = false;
end
end
end
end
end
critical_map(i,j) = test;
end
end

채택된 답변

Friedrich
Friedrich 2012년 2월 3일
Hi,
do you have access to the Image Processing toolbox? If so, you can use the imregionalmin function:
A = randint(10,10,[0 255])
BW = imregionalmin(A,ones(3))
  댓글 수: 1
Saurabh
Saurabh 2012년 2월 6일
Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2012년 2월 3일
Using colfilt():
I = magic(5);
Imin = colfilt(padarray(I,[1 1],inf),[3 3],'sliding',@(x)(min(x,[],1)==x(5,:)));
Imin = Imin(2:end-1,2:end-1);
  댓글 수: 1
Saurabh
Saurabh 2012년 2월 6일
Thanks!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB Report Generator에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by