Create matrix from txt file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mingke
    New Member
    • Dec 2008
    • 16

    Create matrix from txt file

    I have some images 100x100 pixels and save the value of pixels in *.txt file.

    I have to use this txt files as input for iteration. But I don't know how to make the code to recognize the numbers in txt file as a matrix, and iterate it with another txt file. In txt file, the numbers actually lined up as 100 columns and 100 rows. How to make for example A.txt as input for matrix A, and the number in the first column and the first row as A[1][1], or A[1].

    Please, help me. I don't familiar with the langguange. But I have to use C++..

    Thank you for your help
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    Why do you expect each pixel to have only a single numeric value associated with it? A color image would have at least three numeric values associated with each pixel.

    Comment

    • mingke
      New Member
      • Dec 2008
      • 16

      #3
      Originally posted by donbock
      Why do you expect each pixel to have only a single numeric value associated with it? A color image would have at least three numeric values associated with each pixel.

      Because these are grey scale images. So each pixel has one single numeric value (0-225).

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        @OP: if all values are single byte (char) values why do you save the entire matrix as a text file? A simple 10.000 bytes file will do ...

        kind regards,

        Jos

        Comment

        • HabibBhutto
          New Member
          • Jan 2009
          • 17

          #5
          Hi, its so easy... ! dear
          Read ur file in the sequence of char

          like this
          int column = 1;
          int row = 1;

          /* Open and read ur text file here*/
          while( feof( fileptr ) )
          {
          int c = fgetc(fileptr);
          putpixel(r,culu mn,c);
          culumns+=1;
          if (column >= 100)
          {
          column=0;
          r+=1;
          }
          }


          this is simple logic u ma enhance it more according to ur requitements

          Comment

          • mingke
            New Member
            • Dec 2008
            • 16

            #6
            Originally posted by HabibBhutto
            Hi, its so easy... ! dear
            Read ur file in the sequence of char

            like this
            int column = 1;
            int row = 1;

            /* Open and read ur text file here*/
            while( feof( fileptr ) )
            {
            int c = fgetc(fileptr);
            putpixel(r,culu mn,c);
            culumns+=1;
            if (column >= 100)
            {
            column=0;
            r+=1;
            }
            }

            this is simple logic u ma enhance it more according to ur requitements
            Thanks.
            I don't know what is wrong, but these codes aren't working. It's said: `putpixel' cannot be used as a function

            I'm so stupid, so I really need your help

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by mingke
              Thanks.
              I don't know what is wrong, but these codes aren't working. It's said: `putpixel' cannot be used as a function

              I'm so stupid, so I really need your help
              I think you do have an idea what a 'putpixel' function does. Your C/C++ installation doesn't have such a function (or so you say). Wouldn't it be a good idea to find a function with at least similar functionality? Copying and pasting fragments of code an hope that it'll work is not the way to go. Start reading your manuals.

              kind regards,

              Jos

              Comment

              • HabibBhutto
                New Member
                • Jan 2009
                • 17

                #8
                Originally posted by mingke
                Thanks.
                I don't know what is wrong, but these codes aren't working. It's said: `putpixel' cannot be used as a function

                I'm so stupid, so I really need your help
                Oh sorry dear.. !

                u r not stupid .. ! actualy i m... ! first u should to include a graphics hearder file
                and initialize the graphics i think... !

                #include<graphi cs.h>


                void main(void)
                {
                int gd=DETECT, gm=0;

                initgraph(&gd,& gm,"C:\\tc\\bg i ");
                // or specify the drive in which u have installed the TC D: E: whatever

                //place ur code here whatever u want to do

                getch(); // u need conio.h
                closegraph();

                }

                Comment

                Working...