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

조회 수: 16 (최근 30일)
marie lasz
marie lasz 2020년 10월 13일
댓글: marie lasz 2020년 10월 13일
Hello,
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)

채택된 답변

Mathieu NOE
Mathieu NOE 2020년 10월 13일
hello
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);
  댓글 수: 3
Mathieu NOE
Mathieu NOE 2020년 10월 13일
yes - I agree "offset" was not the best name here - a bit confusing because it has nothing to do with shift
it's more the last row of the upper section of the original image
so more or less as you say : offset is the limit value from where the removing of rows will start?
if you 'd prefer to work with "start' and 'end' indexes for upper / lower sections to be kept, that shouddn't be too difficult to do
let me know if you need further assistance
marie lasz
marie lasz 2020년 10월 13일
Thank you very much for your kind response . :-)

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by