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 7694085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:14:18+00:00 2026-05-31T21:14:18+00:00

I am trying to script a greyscale object in a captured image as a

  • 0

I am trying to script a greyscale object in a captured image as a matrix of 0 1 that represents a block of object pixels (or something like object style scaling), i can imagine the manual processing by looping the object, scaling and writing the matrix according to the grade of color,
however i’m looking for intelligent or open source tools,

.NET are preferred,

[Update, to explain in more details]

The original images are colored, however, i’m converting it into 256 greyscale, then i want to scale it into black or white only, so at the end of the day it’s just a black and white picture i want convert it to zero-one matrix,

the following url contains a discussion of how to convert black-white picture to zero-one matrix using a software called imagemagick:

http://studio.imagemagick.org/discourse-server/viewtopic.php?f=1&t=18433

notice the Zero one matrix which demonstrate a dragon face image!, is there any techniques or open source tools that helping me to achieve that?

  • 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-05-31T21:14:19+00:00Added an answer on May 31, 2026 at 9:14 pm

    Something like the following using Emgu OpenCV for .NET would work.

    using Emgu.CV;
    using Emgu.CV.CvEnum;
    using Emgu.CV.Structure;
    using System;
    using System.Drawing;
    using System.IO;
    
    using (Image<Bgr, Byte> img = new Image<Bgr, Byte>("MyImage.jpg")) 
    {
        Matrix<Int32> matrix = new Matrix<Int32>(img.Width, img.Height);
    
        for (int i = 0; i<img.Height;i++)
        {
           for (int j = 0; j<img.Width;j++)
           {
               if (img.Data[i,j,2] == 255 && 
                   img.Data[i,j,1] == 255 && 
                   img.Data[i,j,0] == 255)
               {
                   matrix.Data[i,j] = 0;
               }
               else 
               {
                   matrix.Data[i,j] = 1;
               }
           }
        }
    
        TextWriter tw = new StreamWriter("output.txt");
        for (int i = 0; i<img.Height;i++)
        {
           for (int j = 0; j<img.Width;j++)
           {
               tw.Write(matrix.Data[i,j]);
           }
           tw.Write(tw.NewLine); 
        }
    
    
    }
    

    Note that the snippet above loads colour images and creates a matrix with white as 0 and 1 otherwise.

    In order to load and work with grayscale images
    the Image<Bgr, Byte> becomes an Image<Gray, Byte> and the comparison simplifies to just
    if (img.Data[i,j,0] == 255).

    Also to do the thresholding (conversion from colour to grayscale to black and white), you can use Otsu’s thresholding using the cvThreshold method, using something like :

    int threshold = 150;
    Image<Bgr, Byte> img = new Image<Bgr, Byte>("MyImage.jpg");
    Image<Gray, Single> img2 = img1.Convert<Gray, Single>();
    Image<Gray, Single> img3 = new Image<Gray, Single>(img2.Width, img2.Height);
    CvInvoke.cvThreshold(img2, img3, threshold, 255, THRESH.CV_THRESH_OTSU);    
    

    Other possible tools include

    • convert from ImageMagick and pnmoraw from netpbm, as mentioned in the URL you linked, with example snippet convert lib/dragon_face.xbm pbm: | pnmnoraw.
    • Using PIL (Python Image Library) to iterate through image data and the Python IO functions to write the output data
    • Using System.Drawing.Bitmap specifically the GetPixel method to iterate through the image data, and C# IO functions to write the output data.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to include script and style references that will not break on deployment,
im trying to create a script that opens a file and replace every 'hola'
Im trying to create a script that will post a notification stored in a
I was trying a script to draw graph paper like grids on the canvas
I am currently trying to script a job on SQL Server 2005 that will
I'm trying to create script, that will import keywords from images to database. Keywords
I am trying to script some code that will search a specified folder on
Background: I am trying to script the configuration of Elmah so that, in production,
I'm trying to write script that'll crop and resize large photos into HD Wallpapers.
I am trying to script the automatic input of file, which is as follows

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.