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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:55:10+00:00 2026-06-15T12:55:10+00:00

Hello everybody right now I’m trying to getting grey value for every pixel in

  • 0

Hello everybody right now I’m trying to getting grey value for every pixel in an image
what I mean with grey value is the white or black level from an image let’s say 0 for white and 1 for black. for an example for this image

enter image description here

the value I want will be like

 0 0 0 0 0 0
 0 1 1 1 0 0
 0 0 1 1 0 0
 0 0 1 1 0 0
 0 0 1 1 0 0
 0 0 1 1 0 0
 0 0 1 1 0 0
 0 0 0 0 0 0

is this possible? if yes how to do it with OpenCV in C? or if it’s impossible with OpenCV is there any other library that can do this?

  • 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-15T12:55:10+00:00Added an answer on June 15, 2026 at 12:55 pm

    What you ask is certainly possible but how it can be done depends on a lot of things. If you use C++, on SO we generally expect you to use the C++ interface which means you have a cv::Mat object and loaded the image with something like this: (using namespace cv)

    #include <opencv2/core/core.hpp>
    Mat mat_gray = imread(path, CV_LOAD_IMAGE_GRAYSCALE);
    

    or by

    Mat mat = imread(path); // and assuming it was originally a color image...
    Mat mat_gray;
    cvtColor(mat, mat_gray, CV_BGR2GRAY); //...convert it to grayscale.
    

    Now, if you just want to access pixel values one-by-one, you use _Tp& mat.at<_Tp>(int x,int y);. That is:

    for(int x=0; x<mat_gray.rows; ++x)
      for(int y=0; y<mat_gray.cols; ++y)
        mat_gray.at<uchar>(x,y); // if mat.type == CV_8U
    

    You can look up your type here, which you should use in place of uchar if the mat.type is other than CV_8U.

    As for the pure C interface, you can check this answer. But if you use C++, you should definitely use the C++ interface.

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

Sidebar

Related Questions

Hello everybody I'm trying to replace the 'text' input type to 'password' . And
Hello everybody I'm trying to make my own web site with framework JBoss Netty,
Hello everyBody I've created a slideShow (with left and right arrows) , displaying images
Hello everyBody I've created a slideShow (with left and right arrows) , displaying images
Hello everybody and thanks for reading. I have this html; <i class=icon-plus icon-white> Test
Hello everybody I am trying to change the template of a column in my
Hello Everybody! I got the following error, while trying to test a code for
Hello Everybody now i working with JSF 2.0 and EJB3 and i used Primefaces
Hello everybody I am drawing dynamic table and I want to add header for
Hello everybody my linq to sql selection does not working on dateTime field for

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.