[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #43218] imshear causes more signal spread than
From: |
anonymous |
Subject: |
[Octave-bug-tracker] [bug #43218] imshear causes more signal spread than expected and inconsistent vertical offset |
Date: |
Sun, 14 Sep 2014 19:02:11 +0000 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0 |
Follow-up Comment #1, bug #43218 (project octave):
To improve the accuracy of shearing, I wrote the following imshear variant. It
currently is limited to the crop option (i.e., BBOX = 'crop' in imshear).
function MM = imgshear(M, AXIS, ALPHA)
% -- Custom Function: imgshear(M, AXIS, ALPHA)
% Shear M along AXIS ('x' or 'y') by ALPHA (i.e., slope of shear)
%
% The returned matrix is sheared and cropped to the same dimensions
% as the original matrix. For now, this custom function is preferred
% over imshear in the Octave Forge image package because imshear
% spreads the signal more than expected and has an inconsistent
% vertical offset, as described in the Octave bug tracker item
#42318
% at http://savannah.gnu.org/bugs/?group=octave
% initialize
MM = M;
% if shearing slope is nonzero
if (ALPHA ~= 0)
[h,w] = size(M);
% if shearing is vertical
if (AXIS == 'y')
% add vertical margin
if (ALPHA > 0)
hMargin = ceil((w-1)*ALPHA);
M = [M; zeros(hMargin,w,class(M))];
iBase = h;
else
hMargin = ceil((w-1)*(-ALPHA))+1;
M = [zeros(hMargin,w,class(M)); M];
iBase = h + hMargin;
endif;
% for each sheared column
for col=2:w
hOffset = (col-1)*ALPHA;
iDel = ceil(hOffset);
iBottom = iBase + iDel;
iTop = iBottom - h + 1;
c1 = abs(iDel - hOffset);
c0 = 1 - c1;
MM(:,col) = c0*M(iTop:iBottom,col) +
c1*M(iTop-1:iBottom-1,col);
endfor; % each sheared column
% else if shearing is horizontal
elseif (AXIS == 'x')
% add horizontal margin
if (ALPHA > 0)
wMargin = ceil((h-1)*ALPHA);
M = [zeros(h,wMargin,class(M)) M];
jBase = wMargin + 1;
else
wMargin = ceil((h-1)*(-ALPHA))+1;
M = [M zeros(h,wMargin,class(M))];
jBase = 1;
endif;
% for each sheared row
for row=h-1:-1:1
wOffset = (h-row)*(-ALPHA);
jDel = floor(wOffset);
jLeft = jBase + jDel;
jRight = jLeft + w - 1;
c1 = abs(jDel - wOffset);
c0 = 1 - c1;
MM(row,:) = c0*M(row,jLeft:jRight) +
c1*M(row,jLeft+1:jRight+1);
endfor; % each sheared column
endif; % shearing direction specified
endif; % shearing slope is nonzero
endfunction;
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?43218>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/