I would like to calculate the maximum number of translated images along the direction of a given axis. I know about ordfilt2 , however I would like to avoid using the Image Processing Toolbox.
So, here is the code that I still have:
imInput = imread('tire.tif'); n = 10; imMax = imInput(:, n:end); for i = 1:(n-1) imMax = max(imMax, imInput(:, i:end-(ni))); end
Is it possible to avoid using a for loop to speed up the calculation and, if so, how?
The first edit . Using Octave code for im2col is actually 50% slower.
Second edit : preliminary highlighting did not improve the result.
sz = [size(imInput,1), size(imInput,2)-n+1]; range_j = 1:size(imInput, 2)-sz(2)+1; range_i = 1:size(imInput, 1)-sz(1)+1; B = zeros(prod(sz), length(range_j)*length(range_i)); counter = 0; for j = range_j % left to right for i = range_i % up to bottom counter = counter + 1; v = imInput(i:i+sz(1)-1, j:j+sz(2)-1); B(:, counter) = v(:); end end imMax = reshape(max(B, [], 2), sz);
Third edit . I will show the timings.
source share