473,327 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Create matrix from txt file

16
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
Jan 16 '09 #1
7 4349
donbock
2,426 Expert 2GB
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.
Jan 16 '09 #2
mingke
16
@donbock

Because these are grey scale images. So each pixel has one single numeric value (0-225).
Jan 17 '09 #3
JosAH
11,448 Expert 8TB
@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
Jan 17 '09 #4
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,culumn,c);
culumns+=1;
if (column >= 100)
{
column=0;
r+=1;
}
}


this is simple logic u ma enhance it more according to ur requitements
Jan 17 '09 #5
mingke
16
@HabibBhutto
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
Jan 18 '09 #6
JosAH
11,448 Expert 8TB
@mingke
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
Jan 18 '09 #7
@mingke
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<graphics.h>


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

initgraph(&gd,&gm,"C:\\tc\\bgi ");
// 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();

}
Jan 18 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: LumisROB | last post by:
Is it possible to create matrixes with vector <vector <double >> ? If it is possible which is the element m23 ? You excuse but I am not an expert Thanks ROB
4
by: L. | last post by:
Hello, I need to generate random Matrices (say of size 5*5), each with an average of X (say X=0.5), but with different values’ range. One matrix should have values in the range of 0-1, while...
6
by: kilter | last post by:
Anyone know of a routine that will return the number of rows and columns in a matrix?
20
by: Frank-O | last post by:
Hi , Recently I have been commited to the task of "translating" some complex statistical algorithms from Matlab to C++. The goal is to be three times as fast as matlab ( the latest) . I've...
2
by: jjiyunlee | last post by:
Hi, I'm new to C (and programming in general), and I have to say that this site has helped me learn a great deal about C (thanks everybody!!). I've looked through several discussions specifically...
2
by: Marco Biagioni | last post by:
After i've tried to update a vb 6.0 project to vb.net, using visual studio utility,i can't read correctly data bytes from a .bmp file to insert them in a matrix to operate on. Using vb 6.0 the...
2
by: Marco Biagioni | last post by:
After i've tried to update a vb 6.0 project to vb.net, using visual studio utility,i can't read correctly data bytes from a .bmp file to insert them in a matrix to operate on. Using vb 6.0 the...
3
by: craziileeboi | last post by:
Hi I have been pulling my hair out trying to figure this out. Please help!!! Here is my project description: By using a pointer to pointers **A and **B and the function calloc() allocate...
5
by: slizorn | last post by:
hi, well this is the file i have to read into the system... <matrix> rows = 2 cols = 2 1 2 2 4 </matrix>
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.