[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.drawing

Straightening Out A Circle?

Craig Parsons

12/6/2004 6:53:00 AM

Folks,

I have a scanned image which is circular, and contains a trace in the
middle of it (for those of you familar with trucks it is a tachograph
chart!).

I want to "flatten" it out, into a straight line. I can't seem to find
any controls which might be able to do this for me.

Does anyone have any ideas, or will I have to write some code to do it
pixel by pixel??

Thanks In Advance.


Craig.


7 Answers

Hans Kesting

12/6/2004 10:27:00 AM

0

Craig Parsons wrote:
> Folks,
>
> I have a scanned image which is circular, and contains a trace in
> the middle of it (for those of you familar with trucks it is a
> tachograph chart!).
>
> I want to "flatten" it out, into a straight line. I can't seem to
> find any controls which might be able to do this for me.
>
> Does anyone have any ideas, or will I have to write some code to
> do it pixel by pixel??
>
> Thanks In Advance.
>
>
> Craig.

I don't think there are standard classes for this, you have to write your own.

It would be something like:
- find the position / size / center of the circle
- find the start angle of the trace
- follow the trace in angle/radius coordinates
(possibly: step through the angle-range with some resolution, for a given angle
find the radius where the traceline is)
- plot in new x/y graph, x=recorded angle, y=recorded radius

Nice project. Sorry, I can't help you further with the "how" of these steps.

Hans Kesting


jdmartinez

12/6/2004 6:10:00 PM

0

well, are you only doing this once? if so, wouldn't it just be easier
to flatten it out by hand?

If you need this to be dynamic however, then mr. Kesting's suggestion
holds true ... here is an article that should give you all the details
on accessing and manipulating the pixel data of an image.

http://www.codeproject.com/cs/media/csharpgraphicfil...

Joel Martinez
http://www.... - Orlando .NET User Group
http://www.co... - blog

jdmartinez

12/6/2004 6:12:00 PM

0

well, are you only doing this once? if so, wouldn't it just be easier
to flatten it out by hand?

If you need this to be dynamic however, then mr. Kesting's suggestion
holds true ... here is an article that should give you all the details
on accessing and manipulating the pixel data of an image.

http://www.codeproject.com/cs/media/csharpgraphicfil...

Joel Martinez
http://www.... - Orlando .NET User Group
http://www.co... - blog

jdmartinez

12/6/2004 7:02:00 PM

0

Well, does this have to be a dynamic process? are you only trying to
flatten this data once for display, or will this be an ongoing process?
If only once, then consider just doing it manually (ie. by hand) as
the time it would take to write this tool would probably outweigh the
time to do it by hand.

If however you really need for this to be done dynamically, then Han's
suggestion is in fact what you need to do. Here's a kick ass article
that should show you everything you need to do to access the nitty
gritty pixel data:

http://www.codeproject.com/cs/media/csharpgraphicfil...

Hope that helps,
Joel Martinez
http://www.... - Orlando .NET User Group
http://www.co... - blog

Craig Parsons

12/6/2004 7:40:00 PM

0

Thanks,

It does need to be dynamic as I will want to do it on a scanned image a
lot of times for different images, so thanks very much for the link.


Craig.


<jdmartinez@ea.com> wrote in message
news:1102356066.890001.279730@z14g2000cwz.googlegroups.com...
> Well, does this have to be a dynamic process? are you only trying to
> flatten this data once for display, or will this be an ongoing process?
> If only once, then consider just doing it manually (ie. by hand) as
> the time it would take to write this tool would probably outweigh the
> time to do it by hand.
>
> If however you really need for this to be done dynamically, then Han's
> suggestion is in fact what you need to do. Here's a kick ass article
> that should show you everything you need to do to access the nitty
> gritty pixel data:
>
> http://www.codeproject.com/cs/media/csharpgraphicfil...
>
> Hope that helps,
> Joel Martinez
> http://www.... - Orlando .NET User Group
> http://www.co... - blog
>


Ciaran

12/18/2004 12:45:00 AM

0

I think the best way for this might be to produced a clever transformation
matrix to warp the picture straight using GDI+ in the System.Drawing
namespace. I wouldn't know where to start personally but try reading a bit
about it at www.bobpowell.net/faqmain.htm

Sorry I cant be more help

Ciaran


"Craig Parsons" <craig.parsons@hicpx.com> wrote in message
news:41b4011b$0$9327$ed2619ec@ptn-nntp-reader02.plus.net...
> Folks,
>
> I have a scanned image which is circular, and contains a trace in the
> middle of it (for those of you familar with trucks it is a tachograph
> chart!).
>
> I want to "flatten" it out, into a straight line. I can't seem to find
> any controls which might be able to do this for me.
>
> Does anyone have any ideas, or will I have to write some code to do it
> pixel by pixel??
>
> Thanks In Advance.
>
>
> Craig.
>


Lazarus Lang

12/23/2004 12:14:00 PM

0

"Craig Parsons" <craig.parsons@hicpx.com> wrote in message
news:41b4011b$0$9327$ed2619ec@ptn-nntp-reader02.plus.net...
> I have a scanned image which is circular, and contains a trace in the
> middle of it (for those of you familar with trucks it is a tachograph
> chart!).
>
> I want to "flatten" it out, into a straight line. I can't seem to
find
> any controls which might be able to do this for me.
>
> Does anyone have any ideas, or will I have to write some code to do it
> pixel by pixel??

Yup, pixel by pixel. I couldn't help myself and quickly wrote it.
If I feed this a bitmap with a circle at the center, it returns a bitmap
with
a straight line so I guess it works. (No guarantees though !) :

public static Bitmap UnCircularWarp(Bitmap cb) 'cb stands for circular
bitmap
{
int width = Math.Min(cb.Width, cb.Height);
Bitmap bTemp = new Bitmap((width << 1) + 1, (width >> 1) + 1,
cb.PixelFormat);
double r = width / 2.0f;
for (int x = 0; x < bTemp.Width; ++x)
{

// as X goes from 0 to bTemp.width, alpha goes from PI to -PI
double alpha = Math.PI - Math.PI * 2.0d * (double)x / (double)bTemp.Width;

double cosA = Math.Cos(alpha);
double sinA = Math.Sin(alpha);
for (int y = bTemp.Height - 1; y >= 0; y--)
{
bTemp.SetPixel(
x,
y,
cb.GetPixel(
(int)(Math.Floor(r + (double)y * cosA)), ' circular transform to
determine pos. in circular bitmap
(int)(Math.Floor(r - (double)y * sinA)) ' circular transform to
determine pos. in circular bitmap
)
);
}
}
return bTemp;
}

Basically this creates a bitmap, half the height of the original bitmap (and
twice the width to make
sure that we have enough pixels to show the result.) Then it walks across
the destination (i.e.
unwarped bitmap) and calculates which position this corresponds to in the
cirular (i.e. original)
bitmap. The formula for the inverse image coordinate transform is simply a
circular mapping (i.e.
x = centerX + radius*cos(alhpa)
y = centerY + radius*sin(alpha)
adapted for screen coordinates (where 0,0 lies at the top left instead of
the bottom left)

Keep in mind that this is *hugely* inefficient. SetPixel is not really a
great way to do image warping.
Ideally you'd want to write this in C(++) for speed.

Have fun.

L2