计算导数 [英] calculating the derivative

查看:70
本文介绍了计算导数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要计算每个像素的导数,存储在数组中并显示在文本文件上

我是c#.net的新手。

i计算每个像素的衍生物......并存储在一个数组中...现在我需要在文本文件上显示..我无法知道如何在文本文件上显示....

如果有我的代码中有任何错误请更正我并帮我在文本文件中显示像素值...

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...

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));

                       

                    }


                }



            }



        }
    }
}



我不确定这是否是正确的存储方式在数组中或不... ... plz help mee .....


im not sure if this is the correct way to store in an array or not...plz help mee.....

推荐答案

你应该将它存储在一个数组中。你可以看看我的attemts:

http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/bbc22dbb-7a2e-4ab3-8c8e-8e042f583f62/ [ ^ ]



这个网站上还有很多关于Sobel边缘检测,线路检测和其他内容的文章:

彩色图像边缘检测方法,使用一维线性图像 [ ^ ]

d检测图像中的一条线的角度 [ ^ ]

边缘检测新方法 [ ^ ]



几乎所有的边缘检测都会使用某种导数来找到边缘。
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.


这篇关于计算导数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆