I want to speedup the code. Currently it takes approximately up to 10sec for 4608*3056 resolution image. I want to reduce the processing time as low as possible. Kindly respond me how.
%%PROCESSING IN VERTICAL DIRECTION
diff = 0;sum = 0;total = 0;ver_max = 0;max = 0;diff = uint32(diff);for i = 2:colssum = 0;for j = 2:rowsif(I(j, i) > I(j-1, i))diff = uint32(I(j, i) - I(j-1, i));elsediff = uint32(I(j-1, i) - I(j, i));endif(diff > 20)sum = sum + diff;endendver1(i) = sum;% Find Peak Value
if(sum > max)ver_max = i;max = sum;endtotal = total + sum;endavg = total / cols;subplot(3,1,1);plot (ver1);%%Smoothing by Low Pass Filter
sum = 0;ver = ver1;for i = 21:(cols-21)sum = 0;for j = (i-20):(i+20)sum = sum + ver1(j);endver(i) = sum / 41;endsubplot(3,1,2);plot (ver);%%Filter out Low Threshold Values
for i = 1:colsif(ver(i) < avg)ver(i) = 0;for j = 1:rowsI(j, i) = 0;endendendsubplot(3,1,3);plot (ver);%%PROCESSING IN HORIZONTAL DIRECTION
diff = 0;total = 0;diff = uint32(diff);max = 0;horz_max = 0;for i = 2:rowssum = 0;for j = 2:cols if(I(i, j) > I(i, j-1))diff = uint32(I(i, j) - I(i, j-1));endif(I(i, j) <= I(i, j-1))diff = uint32(I(i, j-1) - I(i, j));endif(diff > 20)sum = sum + diff;endendhor1(i) = sum;% Find Peak Valueif(sum > max)horz_max = i;max = sum;endtotal = total + sum;endaverage = total / rows;subplot(3,1,1);plot (hor1);%%Smoothing by Low Pass Filtersum = 0;horz = hor1;for i = 21:(rows-21)sum = 0;for j = (i-20):(i+20)sum = sum + hor1(j);endhorz(i) = sum / 41;endsubplot(3,1,2);plot (horz);%%Filter out Low Threshold Valuesfor i = 1:rowsif(horz(i) < avg)horz(i) = 0;for j = 1:colsI(i, j) = 0;endendendsubplot(3,1,3);plot (horz);
Best Answer