bugGNU Octave - Bugs: bug #43218, [octave forge] (image) imshear...

 
 

bug #43218: [octave forge] (image) imshear causes more signal spread than expected and inconsistent vertical offset

Submitter:  None
Submitted:  Sat 13 Sep 2014 04:34:01 PM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Inaccurate Result
Status:  None Assigned to:  None
Originator Name:  sepesi Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * other
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 16 Dec 2016 07:31:17 PM UTC, comment #4: 

This issue is still present in Octave 4.2.0 with image-2.6.1.

There is a suggestion of new code in comment #1, but no changeset yet.

Hartmut <hardy>
Mon 15 Sep 2014 07:57:49 PM UTC, comment #3: 

No need for attribution on the imshear suggested fix. If I eventually have significant changes to Octave (I am curious about making Octave more competitive with MatLab in terms of execution speed), I'll get familiar with Octave's code submission process.

- sepesi

Anonymous
Mon 15 Sep 2014 11:09:45 AM UTC, comment #2: 

Thank you for the bug report and patch. Would you be able to submit an hg changeset with your changes? This would make it easier to review and accept the changes while keeping the whole attribution to you.


hg clone http://hg.code.sf.net/p/octave/image
cd image
## fix imshear.m
## make note of changes on NEWS
hg commit NEWS inst/imshear
hg export -o bug43218.patch -r tip


Carnë Draug <carandraug>
Group Member
Sun 14 Sep 2014 07:02:11 PM UTC, comment #1: 

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;


Anonymous
Sat 13 Sep 2014 04:34:01 PM UTC, original submission:  

When the argument ALPHA is less than one, I believe the signal spread should be limited to just one neighboring element. There
also is an unexpected one pixel variance in the sheared image's vertical offset depending on the image height. Both unexpected results are created on my system with the following code:


figure(1);

A = zeros(9,5); A(5,:) = 1;
Au = imshear(A,'y',0.5,'crop');
Ad = imshear(A,'y',-0.5,'crop');
subplot(2,3,1), imagesc(A), colorbar, colormap gray, title('unsheared');
subplot(2,3,2), imagesc(Au), colorbar, colormap gray, title('shear up');
subplot(2,3,3), imagesc(Ad), colorbar, colormap gray, title('shear down');

A(1,:) = [];
Au = imshear(A,'y',0.5,'crop');
Ad = imshear(A,'y',-0.5,'crop');
subplot(2,3,4), imagesc(A), colorbar, colormap gray, title('unsheared');
subplot(2,3,5), imagesc(Au), colorbar, colormap gray, title('shear up');
subplot(2,3,6), imagesc(Ad), colorbar, colormap gray, title('shear down');

figure(2);

A(1,:) = [];
Au = imshear(A,'y',0.5,'crop');
Ad = imshear(A,'y',-0.5,'crop');
subplot(2,3,1), imagesc(A), colorbar, colormap gray, title('unsheared');
subplot(2,3,2), imagesc(Au), colorbar, colormap gray, title('shear up');
subplot(2,3,3), imagesc(Ad), colorbar, colormap gray, title('shear down');

A(1,:) = [];
Au = imshear(A,'y',0.5,'crop');
Ad = imshear(A,'y',-0.5,'crop');
subplot(2,3,4), imagesc(A), colorbar, colormap gray, title('unsheared');
subplot(2,3,5), imagesc(Au), colorbar, colormap gray, title('shear up');
subplot(2,3,6), imagesc(Ad), colorbar, colormap gray, title('shear down');



Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #32087:  bug_imshear2.png added by None (47KiB - image/png)
file #32086:  bug_imshear1.png added by None (52KiB - image/png)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Updated the item)
  • -email is unavailable- added by hardy (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-02-27 mtmiller Carbon-CopyRemoved 80942 -
    2017-08-13 jwe Summaryimage package: imshear causes more signal spread than expected and inconsistent vertical offset [octave forge] (image) imshear causes more signal spread than expected and inconsistent vertical offset
    2016-11-16 mtmiller Release3.6.4 other
        Operating SystemMicrosoft Windows Any
        Summaryimage: imshear causes more signal spread than expected and inconsistent vertical offset image package: imshear causes more signal spread than expected and inconsistent vertical offset
    2014-09-15 carandraug Summaryimshear causes more signal spread than expected and inconsistent vertical offset image: imshear causes more signal spread than expected and inconsistent vertical offset
    2014-09-13 None Attached File- Added bug_imshear1.png, #32086
        Attached File- Added bug_imshear2.png, #32087

    Back to the top

    Powered by Savane 3.13-cf05.
    Corresponding source code