How to use ''offset'' to determine its position ?

Illustration
Greyson - 2020-10-15T11:23:04+00:00
Question: How to use ''offset'' to determine its position ?

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)

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-11-20

the code is intened to remove rows in an image . I tested the code to check it
  • nr is the qty of rows to remove
  • offset defines the upper section rows ( 1 to offset) kept in the output image
  • the removed rows are "1+offset" to "offset+nr"
hope my comments are giving you the answer to your question
you can test it on an image to see the effect
 
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);


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!