I have this code which I got from github. First of all, I didn't get why he is replacing upper part and lower part of pixel rows? what does this upper part and lower part of pixels means here? Secondly, here offset means the position but how a value from left to right, right to left assigns to offset? im_rem(1:offset,:,:) = im(1:offset,:,:); %replace upper part (above removed pixel rows) im_rem(offset+1:H-nr,:,:) = im(offset+nr+1:H,:,:); %replace lower part (below removed pixel rows)
Kshitij Singh answered .
2025-11-20
files = dir('handheld*.jpg'); % as example : only jpeg files with "handheld" in the filename
% main loop
Filename = files.name;
im = imread(Filename); % save for future use
% plot original image
figure(1), imagesc(im);
% apply suggested code %
[H,L] = size(im); % size of original image
% parameters for rows removal
offset = 100; % output image / upper part : we keep rows "1" to "offset" of the original image
nr = 200; % output image / lower part : we keep only rows "1+offset+nr" to "H" (lower end of the original image)
% so basically the new image is the input image from which rows "1+offset" to "offset+nr" have been removed, which is indeed "nr" rows.
im_rem(1:offset,:,:) = im(1:offset,:,:); % upper part (above removed pixel rows)
im_rem(offset+1:H-nr,:,:) = im(offset+nr+1:H,:,:); % lower part (below removed pixel rows)
figure(2), imagesc(im_rem);