Calculate the pixel intensities in an image...

This is a discussion on Calculate the pixel intensities in an image... within the C Programming forums, part of the General Programming Boards category; i want some help regarding the above mentioned title... explaining clearly, the input is an image, and the required output ...

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    5

    Arrow 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. #2
    Registered User
    Join Date
    Jun 2006
    Posts
    5
    pls friends, this is urjent and important for me....pls help...

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    A matrix of pixel intensities sounds strangely like um....a bitmap to me.

  4. #4
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    If you're working in a Windows environment, you may want to check out GetDIBits

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    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?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    18
    after receiving lots of help, I know how to do this for a TIFF image, if that will help you...

  7. #7
    Registered User
    Join Date
    Jun 2006
    Posts
    5
    yeah.....pls do tell me....

  8. #8
    Registered User
    Join Date
    Jun 2006
    Posts
    5
    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++)
    		{
    			fprintf(fp2,"%d",str[i][j]);/* the value read */
    		}
    		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....
    Attached Files Attached Files

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    > 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
    - read the 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.
    http://www.google.co.uk/search?q=bmp+file+format
    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
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    Registered User
    Join Date
    Jun 2006
    Posts
    5
    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. #11
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    Ah - sarcasm - but not today thanks.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading tiff image files?
    By compz in forum C++ Programming
    Replies: 9
    Last Post: 10-30-2009, 04:17 AM
  2. reading gif image pixel Information-help
    By kapil1089thekin in forum C Programming
    Replies: 2
    Last Post: 05-17-2008, 01:13 AM
  3. bilinear interpolation
    By cboard_member in forum Game Programming
    Replies: 5
    Last Post: 03-28-2007, 10:51 PM
  4. Replies: 0
    Last Post: 07-07-2004, 10:18 AM
  5. Replies: 4
    Last Post: 03-02-2003, 08:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21