1

I have an image (taken from my cell phone camera or maybe drawn in paint on my pc) in which I have white background and drawn lines inside a rectangular figure. I am only considered about the stuff inside the rectangle including it's boundary.

Now I want to create an array out of this such that for all the lines the array should have value 1 and for all the free space array should have 0.

I am working on ubuntu and once the array's been created, I use it further in my C program.

Any leads on what software can I use for this? I heard about imagemagick, will that be helpful?

Kindly help. Thanks.

3
  • In which format is your image stored? Is it YUV or RGB or JPEG? If I understand correctly, you are trying to create a negative of the image? Is this a correct understanding? Commented Apr 12, 2013 at 13:31
  • I am not sure what negative would imply, but for all the white space inside the rectangular area, the array should have 0 and for all the drawn lines, it should have 1. I think if I capture it from my camera, it would be JPEG. Commented Apr 12, 2013 at 13:33
  • If your image have the only one format (for example, png with fixed parameters) it would be simpler to use single specific library (in that case - libpng), than to use imagemagic. Commented Apr 12, 2013 at 13:33

1 Answer 1

1

I would follow those steps:

  • Load image (whatever format) with an image processing library. I propose CImg as an easy-to-use library.

  • Apply threshold image and create a b&w version. Here there can be some noise and you may have to play with the threshold value.

  • Detect the large rectangle (this is somewhat tricky) and crop its inside.

Now converting to an array should be easy, just be iterating the pixels and checking if it's black or white.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the reply. Actually I have until now worked with C language only. I am not sure how to use the Clmg library. Can you tell me what methods shall I use for loading, applying threshold and detect the large rectangle using that library. Or will the link you attached along, will be able to guide me through? Thanks again.
Yes, it's C++ and it might be not not that easy for you. I haven't used it for a couple of years but I remember it was one of the simplest to use, plus it's only one header file. Check the tutorial
Thanks. Once I get the array with 0s and 1s from this method, I will be able to use that in my C program?
I'm not sure what you mean. You need to code/compile in C++ to use this library. If you you convert to to a C array you can still handle it with your C code.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.