| | |
image manipulation
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2005
Posts: 14
Reputation:
Solved Threads: 0
hi
i want to find the correlation coefficient between two images, so i have to apply mathmatical equations on them.
i want to ask how can i convert the image to a form that can deal with maths' operator like -, /, XOR after reading it from a file.
i try to convert it to byte or a string to make calculations but that does not work! :cry:
i want to find the correlation coefficient between two images, so i have to apply mathmatical equations on them.
i want to ask how can i convert the image to a form that can deal with maths' operator like -, /, XOR after reading it from a file.
i try to convert it to byte or a string to make calculations but that does not work! :cry:
You will have to read the image into a two dimensional structure, maybe a two dimensional array, and then apply the operations to corresponding elements at position x and y.
You could do this even with a single dimensional array, but that is rather unintuitive in my opinion.
C# Syntax (Toggle Plain Text)
ResultantImage[x][y] = Image1[x][y] - Image2[x][y]
You could do this even with a single dimensional array, but that is rather unintuitive in my opinion.
•
•
Join Date: Dec 2005
Posts: 14
Reputation:
Solved Threads: 0
hi
thanks for your reply;
i deal with two black and white images(binary images); and want to make correlation method calculations on them to find correlation coefficient.
so the pixel value is (0,0,0) for black or (1,1,1) for white.
that i use the GetPixel then test if its black or white and set an integer to 0 if black or 1 if white.
and then deal with these integer instead of converting the images to array int as you suggest.
this is the code below; its behind the correlation coeff button; I have error when debugging at the bold font:
note: im sure that both images have the same size.
any suggestions...
int q=0;
int w=0;
Bitmap a = (Bitmap)Image.FromFile("C:\\standard\\test1.bmp");
Bitmap b = (Bitmap)Image.FromFile("C:\\standard\\test2.bmp");
int x=0;
int y=0;
int i=0;
int j=0;
for(i=0;i<=a.Height;i++)
{
for(j=0;j<=a.Width;j++)
{
Color c=a.GetPixel(i,j);
Color r=b.GetPixel(i,j);
if (c.R == 0 && c.G == 0 && c.B == 0)
q = 0;
if (c.R == 1 && c.G == 01 && c.B == 1)
q = 1;
if (r.R == 0 && r.G == 0 && r.B == 0)
w = 0;
if (r.R == 1 && r.G == 1 && r.B == 1)
w = 1;
x+=q;
y+=w;
}
}
int s=0;
int ss=0;
int sss=0;
for(i=0;i<=a.Height;i++)
{
for(j=0;j<=a.Width;j++)
{
Color c=a.GetPixel(i,j);
Color r=b.GetPixel(i,j);
if (c.R == 0 && c.G == 0 && c.B == 0)
q = 0;
if (c.R == 1 && c.G == 01 && c.B == 1)
q = 1;
if (r.R == 0 && r.G == 0 && r.B == 0)
w = 0;
if (r.R == 1 && r.G == 1 && r.B == 1)
w = 1;
s+=(q-x)*(q-x);
ss+=(w-y)*(w-y);
}
}
for(i=0;i<=a.Height;i++)
{
for(j=0;j<=a.Width;j++)
{
Color c=a.GetPixel(i,j);
Color r=b.GetPixel(i,j);
if (c.R == 0 && c.G == 0 && c.B == 0)
q = 0;
if (c.R == 1 && c.G == 01 && c.B == 1)
q = 1;
if (r.R == 0 && r.G == 0 && r.B == 0)
w = 0;
if (r.R == 1 && r.G == 1 && r.B == 1)
w = 1;
sss+=(q-x)*(w-y);
}
}
double corr;
corr = sss/(System.Math.Sqrt(((s*s)+(ss*ss))));
label1.Text = corr.ToString();
}
thanks for your reply;
i deal with two black and white images(binary images); and want to make correlation method calculations on them to find correlation coefficient.
so the pixel value is (0,0,0) for black or (1,1,1) for white.
that i use the GetPixel then test if its black or white and set an integer to 0 if black or 1 if white.
and then deal with these integer instead of converting the images to array int as you suggest.
this is the code below; its behind the correlation coeff button; I have error when debugging at the bold font:
note: im sure that both images have the same size.
any suggestions...
int q=0;
int w=0;
Bitmap a = (Bitmap)Image.FromFile("C:\\standard\\test1.bmp");
Bitmap b = (Bitmap)Image.FromFile("C:\\standard\\test2.bmp");
int x=0;
int y=0;
int i=0;
int j=0;
for(i=0;i<=a.Height;i++)
{
for(j=0;j<=a.Width;j++)
{
Color c=a.GetPixel(i,j);
Color r=b.GetPixel(i,j);
if (c.R == 0 && c.G == 0 && c.B == 0)
q = 0;
if (c.R == 1 && c.G == 01 && c.B == 1)
q = 1;
if (r.R == 0 && r.G == 0 && r.B == 0)
w = 0;
if (r.R == 1 && r.G == 1 && r.B == 1)
w = 1;
x+=q;
y+=w;
}
}
int s=0;
int ss=0;
int sss=0;
for(i=0;i<=a.Height;i++)
{
for(j=0;j<=a.Width;j++)
{
Color c=a.GetPixel(i,j);
Color r=b.GetPixel(i,j);
if (c.R == 0 && c.G == 0 && c.B == 0)
q = 0;
if (c.R == 1 && c.G == 01 && c.B == 1)
q = 1;
if (r.R == 0 && r.G == 0 && r.B == 0)
w = 0;
if (r.R == 1 && r.G == 1 && r.B == 1)
w = 1;
s+=(q-x)*(q-x);
ss+=(w-y)*(w-y);
}
}
for(i=0;i<=a.Height;i++)
{
for(j=0;j<=a.Width;j++)
{
Color c=a.GetPixel(i,j);
Color r=b.GetPixel(i,j);
if (c.R == 0 && c.G == 0 && c.B == 0)
q = 0;
if (c.R == 1 && c.G == 01 && c.B == 1)
q = 1;
if (r.R == 0 && r.G == 0 && r.B == 0)
w = 0;
if (r.R == 1 && r.G == 1 && r.B == 1)
w = 1;
sss+=(q-x)*(w-y);
}
}
double corr;
corr = sss/(System.Math.Sqrt(((s*s)+(ss*ss))));
label1.Text = corr.ToString();
}
Comment out all the other irrelevant code in the loop and other irrelevent code after the loop so that only this remains.
See if the error comes up again. If not, keep on adding lines until you get the error, and try to see what are the values of i and j this happens.
C# Syntax (Toggle Plain Text)
for(i=0;i<=a.Height;i++) {<blockquote>for(j=0;j<=a.Width;j++) {<blockquote>Color c=a.GetPixel(i,j);</blockquote>}</blockquote>}
•
•
Join Date: Dec 2005
Posts: 14
Reputation:
Solved Threads: 0
hi
at last i have an int result and i want to display it in the form
the label deal with charachter only so i want to use MsgBox like this:
corr = sss/(System.Math.Sqrt(((s*s)+(ss*ss))));
string corrv = corr.ToString();
MessageBox.Show(corrv, "correlation coeficiant");
But the box give a charachter result like this "NAN"
how can i display the integer value
thankx
at last i have an int result and i want to display it in the form
the label deal with charachter only so i want to use MsgBox like this:
corr = sss/(System.Math.Sqrt(((s*s)+(ss*ss))));
string corrv = corr.ToString();
MessageBox.Show(corrv, "correlation coeficiant");
But the box give a charachter result like this "NAN"
how can i display the integer value
thankx
NAN is short for "Not A Number". You get this for values like infinity. Check the values of
Also use [code][/code] when posting code.
sss and (s*s)+(ss*ss). Most probably either both of them are 0 or the (s*s)+(ss*ss)value is zero. You should know already that 0 divided by 0 is undefined and any number defined by 0 is also undefined. You should check for these conditions before dividing. Also use [code][/code] when posting code.
![]() |
Similar Threads
- animated pictures and .GIF files (Graphics and Multimedia)
- Auto replace hotlinked Image Javascript? (JavaScript / DHTML / AJAX)
- Image functions in php (PHP)
- Can I make a Java Image Editing Photshop-like program (Java)
- converting BMPs to AVI (Game Development)
- What Language is used in software like Adobe Photoshop? (C++)
Other Threads in the C# Forum
- Previous Thread: Error Throwing In Calculator Code When Divided By '0'
- Next Thread: Help Resizing Image, PLEASE!!
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# check checkbox client color combobox control conversion csharp custom customactiondata database datagrid datagridview dataset date/time datetime datetimepicker degrees development dll draganddrop drawing encryption enum event excel file filename files form format forms function gdi+ gis gtk httpwebrequest image index input install java label list listbox mandelbrot math mouseclick mysql operator outlook2003 path photoshop picturebox pixelinversion pixelminversion post programming radians regex remote remoting richtextbox serialization server sleep socket sql statistics stream string table text textbox thread time timer tutorial update usercontrol validation visualstudio webbrowser webcam wia windows winforms wpf xml






