# Thread: Calculate the pixel intensities in an image...

1. ## Calculate the pixel intensities in an image...

i want some help regarding the above mentioned title...

explaining clearly, the input is an image, and the required output is the 2-dimensional array, i.e., a matrix of the pixel intensities...
this array is an integer array, 'cause i understand a pixel intensity is and integer...right???
actually, what i mean is representing the entire image as an integer matrix, and any manipulations of the matrix results in the modification of the image.

/*
the range of colors intended to be identified is about 0-255, cause, an integer, being 4 bytes, and 2^4 is 8, there can 256 combinations of 0s and 1s...and, 0 indicates white and 255, black...*/

2. pls friends, this is urjent and important for me....pls help...

3. A matrix of pixel intensities sounds strangely like um....a bitmap to me.

4. If you're working in a Windows environment, you may want to check out GetDIBits

5. explaining clearly, the input is an image, and the required output is the 2-dimensional array, i.e., a matrix of the pixel intensities...
So you take an image, say a BMP file, and print the values for eaxh pixel?

6. after receiving lots of help, I know how to do this for a TIFF image, if that will help you...

7. yeah.....pls do tell me....

8. Code:
```#include <stdio.h>
/* This takes in as input, an image file
and gives as output the 2D array or
a matrix representation of the image
whose elements are the intensities of the pixel
*/
int main()
{
FILE *fp1, *fp2;
int i,j;
int str[50][50];
fp1 = fopen("pic.bmp", "r"); /* Input, the image file in the bin folder */
fp2 = fopen("pic.doc","w");
for(i=0;i<50;i++)
{
for(j=0;j<50;j++)
{
fscanf(fp1,"%d",str[i][j]);
}
}
for(i=0;i<50;i++)
{
for(j=0;j<50;j++)
{
}
printf("\n");
}
printf("Hello, world\n");

return 0;
}```
Greetings!
This is the program i have written. I guess this does read the picture, takes in the values of the pixels. And i have printed the ouput matrix to a word doc. And lo! i get the following output. I now wanna know if this is the real procedure.
If there are any built-in C functions that calculate the pixel intensities, do tell me...

The output of the above program is attached...thanks in advance....

9. > pls friends, this is urjent and important for me....pls help...
1. Lose the cryptic kiddy speak of abbreviating everything
2. http://www.catb.org/~esr/faqs/smart-...ns.html#urgent

> I now wanna know if this is the real procedure.
I'm amazed it didn't crash, given the number of basic C mistakes.

But in terms of
- open the input file
- do some calculations
- write results
I suppose you're on the right track (though there is much to do)

> fp1 = fopen("pic.bmp", "r");
BMP is a binary file, so you should probably use "rb"

> fscanf(fp1,"%d",str[i][j]);
1. BMP files are binary, so you can't use text conversion functions
2. you forgot the & on the variable anyway

Reading BMP files is more involved than that.
BMP files have
- a header describing the bitmap file
- an optional colour table
- the bitmap data, possibly compressed

> If there are any built-in C functions that calculate the pixel intensities, do tell me...
No there isn't - do it yourself.
I found a handy function which may assist you, if you get as far as reading RGB values from the bitmap file.
http://vision.nyu.edu/Tips/Tips/RGBTip.html

> pic.doc (12.3 KB, 0 views)
Pick less proprietary (and less buggy) file formats like .txt

10. Thanks for the immense help, Sir.
I shall soon learn the basics of Bitmap and improve this program.
Also, I shall hereafter take care about each of the programming nuances.
Thanking you for instilling in me the confidence, encouraging me to code better, and, for the best link I ever received, "How to Ask Questions The Smart Way", thanks a lot, Sir.
Shall soon post the algorithm of the program I am working on.
Regards
-Sharmontime

11. Ah - sarcasm - but not today thanks.