Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i need to calculate the derivative of each and every pixel ,store in an array and display on a text file
im new to c#.net..
i calculated the derivate of each pixel..and stored in an array... now i need to display on a text file.. i couldnt knw how to display on a text file....
if there are any mistakes in my code please correct me an d help me to display the pixel values on a text file...
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace derivative
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Bitmap newbitmap;
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
            if (open.ShowDialog() == DialogResult.OK)
            {
                pictureBox1.ImageLocation = open.FileName;
                newbitmap = new Bitmap(open.FileName);
                //opened = true;
                /* System.Drawing.Image img = System.Drawing.Image.FromFile( open.FileName     );
                 MessageBox.Show("Width: " + img.Width + ", Height: " + img.Height);*/
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Color n = new Color();
            int x;
            int y;
            int []s;
            s = new int[1000];
            int a;
            for (a = 0; a < s.Length;a++)
            {
                 for (x = 1; x <= newbitmap.Width - 1; x++)
             
                {

                    for (y = 1; y <= newbitmap.Height - 1; y++)
                  
                    {
                       


                    

//derivative of each pixel
                      
                        s[a] = (int)((newbitmap.GetPixel(x + 1, y).R) + (newbitmap.GetPixel(x - 1, y).R) + (newbitmap.GetPixel(x, y + 1).R) + (newbitmap.GetPixel(x, y - 1).R) - (newbitmap.GetPixel(x, y).R * 4));

                       

                    }


                }



            }



        }
    }
}

im not sure if this is the correct way to store in an array or not...plz help mee.....
Posted
Updated 3-Apr-13 4:40am
v2
Comments
[no name] 3-Apr-13 10:42am    
What do mean by "display on a text file"? Do you mean that you want to save the data in a text file?

1 solution

You should definatly store it in an array. You could take a look at my attemts here:
http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/bbc22dbb-7a2e-4ab3-8c8e-8e042f583f62/[^]

There are also a bunch of articles about Sobel edge detection, Line detection and other stuff here on this site:
Method for Edge Detection in Color Images, Using 1-Dimensional Liner Image[^]
Detect the Angle of a Line in an Image[^]
New Method of Edge Detection[^]

Nearly all edge detections shemes use some kind of derivative to find the edges.
 
Share this answer
 
v2
Comments
laliii 3-Apr-13 11:38am    
is this a correct way to store in an array....what i did is correct ie storing in an array...??
Kenneth Haugland 3-Apr-13 11:47am    
You should use the CopyPixel method.
laliii 3-Apr-13 12:39pm    
could u plz explain it...i need to store all the derivative values to an array and want to display it ...
plz write a code for it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900