Welcome Guest Search | Active Topics | Members

Problem with coordinates after transfromation Options
midibase
Posted: Sunday, September 16, 2007 10:26:52 AM
Rank: Member
Groups: Member

Joined: 9/16/2007
Posts: 4
Points: 0
hello,
can anyone help me?
I write an application where I need to transform an Image. (See first.jpg)
I drag the blue lines to the new positions (see secound.jpg)
After I push a button I got the result from transformation very well (see third.jpg)

But my blue polygone has the wrong position (it has the old position) but I need it on the result of transformation.
I have no idea how I could solve this.

Secound question.
Is there any possibility to move the bitmap inside the BitmapViewer (Control) by set x,y coordinates or is it only possible
to use the ImageAlligement?

thangs for your help


Code Snipes:
Code:
      private void button2_Click(object sender, EventArgs e) {
            try {
                //Apply projective transform and store the result.
                GMBitmap.Bitmap.ApplyInPlace = false;

                GMBitmap.Bitmap = GMBitmap.Bitmap.Transforms.ProjectivePoints(
                    destPointX[0], destPointY[0],
                    destPointX[1], destPointY[1],
                    destPointX[2], destPointY[2],
                    destPointX[3], destPointY[3],
                    oldPointX[0], oldPointY[0],
                    oldPointX[1], oldPointY[1],
                    oldPointX[2], oldPointY[2],
                    oldPointX[3], oldPointY[3],
                    0,
                    InterpolationMode.InterpolationModeHighQuality,
                    FitMode.FitModeCircumscribed);

                GMBitmap.Bitmap.ApplyInPlace = true;

                for (int i = 0; i < 4; i++) {
                    oldPointX[i] = destPointX[i];
                    oldPointY[i] = destPointY[i];
                }
            } catch (Exception ex) {
                lbMessage.Text = ex.Message;
            }
        }






midibase attached the following image(s):
first.jpg
secound.jpg
third.jpg

Dmitry
Posted: Wednesday, September 19, 2007 1:08:32 AM
Rank: Advanced Member
Groups: Administration , Member

Joined: 8/3/2003
Posts: 586
Points: 588
Hello,

It is hard to answer your question without looking through you code which manages selection and draw a polygon. It seems that you display image in the BitmapViewer, so after you apply projective transform you should calibrate polygon points taking into account that new image is diplayed in the center of control.

No, you cannot specify x and y coordinates from where bitmap is displayed inside the control.

Sincerely yours,
Dmitry Sevostyanov.
midibase
Posted: Wednesday, September 19, 2007 7:22:34 AM
Rank: Member
Groups: Member

Joined: 9/16/2007
Posts: 4
Points: 0
Yes you're right. so I post the code for you to help me
THX

File Attachment(s):
DragArea.rar (6kb) downloaded 66 time(s).


Dmitry
Posted: Tuesday, October 02, 2007 11:02:02 PM
Rank: Advanced Member
Groups: Administration , Member

Joined: 8/3/2003
Posts: 586
Points: 588
Hello,

Sorry for late answer.

As the size of image is changed while it is tranformed by projective points algorithm, you should move position of your polygon after transformation. You can calculate polygon offset in particular case only when source polygon is corner-aligned rectangle: (0, 0, image width, image height). In common case there is no way to calculate offset values because of implementation aspects of algorithm.

So offset will be:
  • X position: destPointX[i] -= minDestX, where minDestX - minimum x-coordinate value of destination polygon;
  • Y position: destPointY[i] -= minDestY, where minDesty - minimum y-coordinate value of destination polygon;

    Pay attention that there is a problem in DragRectangle setter - points were calcualted wrong. The correct version of setter is the following:
    Code:
    public System.Drawing.Rectangle DragRectangle {
        get { return dragRec; }
        set {
            dragRec = value;
            //'Init source points
            destPointX[0] = oldPointX[0] = dragRec.X;
            destPointY[0] = oldPointY[0] = dragRec.Y;
            //destPointX[1] = oldPointX[1] = dragRec.Width;
            destPointX[1] = oldPointX[1] = dragRec.Right;
            destPointY[1] = oldPointY[1] = dragRec.Y;
            //destPointX[2] = oldPointX[2] = dragRec.Width;
            destPointX[2] = oldPointX[2] = dragRec.Right;
            //destPointY[2] = oldPointY[2] = dragRec.Height;
            destPointY[2] = oldPointY[2] = dragRec.Bottom;
            destPointX[3] = oldPointX[3] = dragRec.X;
            //destPointY[3] = oldPointY[3] = dragRec.Height;
            destPointY[3] = oldPointY[3] = dragRec.Bottom;
        }
    }
    Click handler of "Tranform" button will be the following
    Code:
    private void button2_Click(object sender, EventArgs e) {      
        try {      
          //Apply projective transform and store the result.
          GMBitmap.Bitmap.ApplyInPlace = false;      

            int widthBefore = GMBitmap.Bitmap.Data.Width;
            int heightBefore = GMBitmap.Bitmap.Data.Height;

            GMBitmap.Bitmap = GMBitmap.Bitmap.Transforms.ProjectivePoints(
                destPointX[0], destPointY[0],
                destPointX[1], destPointY[1],
                destPointX[2], destPointY[2],
                destPointX[3], destPointY[3],
                oldPointX[0], oldPointY[0],
                oldPointX[1], oldPointY[1],
                oldPointX[2], oldPointY[2],
                oldPointX[3], oldPointY[3],
                0,
                InterpolationMode.InterpolationModeHighQuality,
                FitMode.FitModeCircumscribed);

            GMBitmap.Bitmap.ApplyInPlace = true;

            double minDestX = double.MaxValue;
            double minDestY = double.MaxValue;

            for (int i = 0; i < 4; i++)
            {
                if (minDestX > destPointX[i])
                    minDestX = destPointX[i];
                if (minDestY > destPointY[i])  
                    minDestY = destPointY[i];
            }

            for (int i = 0; i < 4; i++)
            {
                destPointX[i] -= minDestX;
                destPointY[i] -= minDestY;
            }

            for (int i = 0; i < 4; i++) {
                oldPointX[i] = destPointX[i];
                oldPointY[i] = destPointY[i];
            }
        } catch (Exception ex) {
            lbMessage.Text = ex.Message;
        }
    }
    As you develop .NET application I advise you to upgrade Graphics Mill for ActiveX to Graphics Mill for .NET. Graphics Mill for .NET is native for .NET platform and has a lot of improvements in comparison with ActiveX version. More information you can read on our site.

    Sincerely yours,
    Dmitry Sevostyanov.
  • midibase
    Posted: Thursday, October 04, 2007 5:08:18 AM
    Rank: Member
    Groups: Member

    Joined: 9/16/2007
    Posts: 4
    Points: 0
    First of all, thanks for your help, I check it when I have time at tomorrow .

    Because upgrade Graphics Mill for ActiveX to Graphics Mill for .NET.
    I would do it but there is a big problem:
    I need the Transform-Method and it has only the Version "Graphics Mill for ActiveX"
    Or it isn't right?

    midibase
    Andrew
    Posted: Thursday, October 04, 2007 9:17:44 PM

    Rank: Advanced Member
    Groups: Administration , Member

    Joined: 8/2/2003
    Posts: 709
    Points: 108
    Could you tell more detailed what exact functionality you mean? The Transforms property is just a holder for all image processing methods. The similar property is available in .NET version.

    To tell the truth I cannot remember any ActiveX version feature which is not available in .NET version. At least all features required to build the application you posted here are available there.

    If you mean arbitrary affine/projective transforms, they are available in the .NET version. Here you can read how about it (the first part of the article is the math stuff, GM-related information begins in the middle of the article):

    http://graphics-mill-docs.aurigma.com/Docs/GraphicsMilldotNET/Transformations.htm

    Sincerely yours,
    Andrew Simontsev from Aurigma Team
    Users browsing this topic
    Guest


    Forum Jump
    You cannot post new topics in this forum.
    You cannot reply to topics in this forum.
    You cannot delete your posts in this forum.
    You cannot edit your posts in this forum.
    You cannot create polls in this forum.
    You cannot vote in polls in this forum.

    Main Forum RSS : RSS

    YAFVision Theme Created by Jaben Cargman (Tiny Gecko)
    Yet Another Forum.net version 1.9.1.6 running under Cuyahoga.
    Copyright © 2003-2006 Yet Another Forum.net. All rights reserved.