Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8144147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:17:41+00:00 2026-06-06T13:17:41+00:00

I’m trying to save the value of each pixel in a gray scale image

  • 0

I’m trying to save the value of each pixel in a gray scale image into a text file. For example, if a pixel location (x, y) has a value of 255 (pure white), an 255 will be saved in the correspondent coordinate in a text file.

Here’s my code. It’s a WinForm applicaton in Emgu CV 2.4.0, MSFT Visual Studio 2010 and MSFT .NET 4.0 on an x86 machine.

OpenFileDialog OpenFile = new OpenFileDialog();//open an image file.
        if (OpenFile.ShowDialog() == DialogResult.OK)
        {
            Image<Bgr, Byte> My_Image = new Image<Bgr, byte>(OpenFile.FileName);//Read the file as an Emgu.CV.Structure.Image object.
            Image<Gray, Byte> MyImageGray = new Image<Gray, Byte>(My_Image.Width, My_Image.Height);//Initiate an Image object to receive the gray scaled image. 
            CvInvoke.cvCvtColor(My_Image.Ptr, MyImageGray.Ptr, COLOR_CONVERSION.CV_RGB2GRAY);//convert the BGR image to gray scale and save it in MyImageGray
            CvInvoke.cvNamedWindow("Gray");
            CvInvoke.cvShowImage("Gray", MyImageGray.Ptr);
            StreamWriter writer = File.CreateText("test.txt");//Initiate the text file writer
            Gray pixel;
            //try to iterate through all the image pixels.
            for (int i = 0; i < MyImageGray.Height; i++)
            {
                for (int j = 0; j < MyImageGray.Width; j++)
                {
                    pixel = MyImageGray[j, i];
                    Console.WriteLine(string.Format("Writing column {0}", j));//debug output
                    writer.Write(string.Format("{0} ",pixel.Intensity));
                }
                writer.WriteLine();
            }
        }

I tried to run it but for some reason, it got stuck after i=0 and j=MyImageGray.Width-1. It should go to process the next row but the whole Visual Studio 2010 and the application froze. By froze I mean the window of my application can not be moved and the cursor in the VS can not move either. I have to kill the application by pressing Shift+F5. Meanwhile, I got a “A first chance exception of type ‘Emgu.CV.Util.CvException’ occurred in Emgu.CV.dll” when I’m reading the (0, 414) pixel. Actually the debug message looks like:

Writing column 413
WritinA first chance exception of type 'Emgu.CV.Util.CvException' occurred in     Emgu.CV.dll
g column 414
Writing column 415

I tried to put a break point at i=MyImageGray.Width-1 and the program seems to freeze before it hit the break point.
I really don’t know what’s wrong in my approach. Any idea would be appreciated and I’m happy to provide more info upon request. Thanks ahead!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T13:17:42+00:00Added an answer on June 6, 2026 at 1:17 pm

    When you access pixel values that way you should use pixel = MyImageGray[i, j]; instead of pixel = MyImageGray[j, i];. First index is row and a second one is column.

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to render a haml file in a javascript response like so:
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a reasonable size flat file database of text documents mostly saved in
I am trying to understand how to use SyndicationItem to display feed which is
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.