Visualize grey scale level image

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 1
Reputation: nash83 is an unknown quantity at this point 
Solved Threads: 0
nash83 nash83 is offline Offline
Newbie Poster

Visualize grey scale level image

 
0
  #1
Sep 13th, 2007
Hello to everybody.I am using microsoft visual c++ compilator 7.0 for image processing.I have wrote down a program that opens a 24 bitmap image and loads it on a 800x 600 matrix after making the average of the RGB bytes.This because I would like to visualize it like a grey scale image.Is this possible?I mean after making the average and loading each value on the matrix how can I visualize it as grey level image?I post the code I hope someone can help me

//program to load a 24 color bitmap on a matrix and visualize its content

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <conio.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <windows.h>
  7.  
  8.  
  9. void load_bitmap(char *,int,int,void *);
  10.  
  11. void main(int argc, char *argv[])
  12. {
  13. int i=0,j=0,w=0,h=0,t=0;
  14. unsigned char *buf = (unsigned char *)malloc(sizeof(unsigned char)*800*600*3);
  15. unsigned char buff[800][600]; //this is the matrix where I want to lad the image
  16. char *name = "polyhedron10.bmp"; //this is the name of the image I want to load (it is present on .cpp file folder)
  17.  
  18. load_bitmap(name,w,h,buf); //member function to open the bitmap image
  19. for(i=0; i<800; i++) for(j=0; j<600; j++){ //double for cycle to load the image
  20. buff[i][j]=(*(buf + t) + *(buf + t + 1) + *(buf + t + 2))/3;
  21. t=t+3;
  22. }
  23. for(i=0; i<800; i++) for(j=0; j<600; j++){ //cycle to visualize content
  24. printf("%d,%d",i,j);
  25. printf(" %d\n ",buff[i][j]);
  26. Sleep(5);
  27. }
  28. }
  29.  
  30. void load_bitmap(char* filename,int width, int height, void* buffer)
  31. {
  32.  
  33. FILE* fp;
  34.  
  35. if((fp = fopen(filename, "rb")) == NULL) //check it is a bitmap image
  36. {
  37. printf("it is not a bitmap”s�B\n");
  38. return;
  39. }
  40.  
  41. printf("pointer to fp is %d\n",fp);
  42. fread(buffer, sizeof(BYTE), 600*800*3, fp);
  43. fclose(fp);
  44. }
Last edited by Ancient Dragon; Sep 14th, 2007 at 12:07 am. Reason: add code tags and remove color tags
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum


Views: 1733 | Replies: 0
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC