SlideShare ist ein Scribd-Unternehmen logo
1 von 4
Computer Project for Chapter 1
    1. (a) Obtain a set of YCrCb images for the set of 256x256 RGB Lena
       Images (Lena256C.bmp is a color input image)
       (b) Obtain a set of HIS images for the set of RGB images
    2. Obtain images subsampled with (2:1)x(2:1), (4:1)x(4:1) from 512x512
       Lena image. Display the original image and the subsampled ones with
       the same size and compare their qualities (Le512.raw is a gray input
       image).
    3. Obtain 1-, 2-, 4-, 6-bit images from 8-bit 512x512 Lena image.
       Display the original image and the outputs, and compare their
       qualities (Le512.raw is a gray input image).

Note:
1. Lena256C is a bitmap color image. You should read it out in your
program using the following referenced function in C++, and then RGB
images will be stored in * * * array for further processing

======
unsigned char*** ReadRGB(char *str, int &height, int &width, int &bit)

{

        unsigned char ***rgb=NULL;

        FILE *fp;

        if((fp=fopen(str,"rb"))==NULL)

        {

               // AfxMessageBox("file open error");

               return(rgb);

        }

        BITMAPFILEHEADER bmpfileheader;

        fread(&bmpfileheader,sizeof(BITMAPFILEHEADER),1,fp);
BITMAPINFOHEADER bmpinfoheader;

       fread(&bmpinfoheader,sizeof(BITMAPINFOHEADER),1,fp);

       bit=bmpinfoheader.biBitCount;

       int byte_count=bit/8;

       height=bmpinfoheader.biHeight;

       width=bmpinfoheader.biWidth;

       if(bit!=24&&bit!=8)

       {

              // AfxMessageBox("No 8bit or 24bit image!.");

              fclose(fp);

              return(rgb);

       }

       rgb=(unsigned char***)malloc(byte_count*sizeof(unsigned
char**));

       for(int i=0;i<byte_count;i++)

       {

              rgb[i]=(unsigned char**)malloc(height*sizeof(unsigned
char*));

              for(int y=0;y<height;y++)

                       rgb[i][y]=(unsigned
char*)malloc(width);

       }
for(int y=0;y<height;y++)

              for(int x=0;x<width;x++)

              {

                      for(i=0;i<byte_count;i++)

                      {

                             rgb[byte_count-i-1][x][y]=getc(fp);

                      }

              }

       fclose(fp);

       return(rgb);

}
======
2. Lena.raw is a 8-bit gray scale image. You may refer the following code:
======
float x[256][256], y[256][256]; //x array for in put, y array for output
FILE *fo ,*fs ;
       int i,j;

        fo=fopen("lena.raw","rb");//for reading raw image
        for(i=0;i<256;i++)
        {
                for(j=0; j<256; j++)
                {
     x[i][j]=(float)getc(fo);
                }
        }
fs=fopen("output.raw","wb");// for writing raw image
  for(i=0;i<256;i++)
  {
for(j=0;j<256;j++)
        {
                putc((unsigned char)y[i][j],fs);
        }
    }

}

Weitere ähnliche Inhalte

Was ist angesagt?

Chapter 7 - Input Output Statements in C++
Chapter 7 - Input Output Statements in C++Chapter 7 - Input Output Statements in C++
Chapter 7 - Input Output Statements in C++Deepak Singh
 
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingDynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingMeghaj Mallick
 
Abstracting over Execution with Higher Kinded Types
Abstracting over Execution with Higher Kinded TypesAbstracting over Execution with Higher Kinded Types
Abstracting over Execution with Higher Kinded TypesPhilip Schwarz
 
Crystal Ball Event Prediction and Log Analysis with Hadoop MapReduce and Spark
Crystal Ball Event Prediction and Log Analysis with Hadoop MapReduce and SparkCrystal Ball Event Prediction and Log Analysis with Hadoop MapReduce and Spark
Crystal Ball Event Prediction and Log Analysis with Hadoop MapReduce and SparkJivan Nepali
 
built in function
built in functionbuilt in function
built in functionkinzasaeed4
 
GECon2017_Cpp a monster that no one likes but that will outlast them all _Ya...
GECon2017_Cpp  a monster that no one likes but that will outlast them all _Ya...GECon2017_Cpp  a monster that no one likes but that will outlast them all _Ya...
GECon2017_Cpp a monster that no one likes but that will outlast them all _Ya...GECon_Org Team
 
GECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them allGECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them allYauheni Akhotnikau
 
Simulador carrera de caballos desarrollado en C++
Simulador carrera de caballos desarrollado en C++Simulador carrera de caballos desarrollado en C++
Simulador carrera de caballos desarrollado en C++Santiago Sarmiento
 
Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)Ahmed Khateeb
 
Garbage Collection
Garbage CollectionGarbage Collection
Garbage CollectionEelco Visser
 
Probability of finding a single qubit in a state
Probability of finding a single qubit in a stateProbability of finding a single qubit in a state
Probability of finding a single qubit in a stateVijayananda Mohire
 

Was ist angesagt? (20)

Chapter 7 - Input Output Statements in C++
Chapter 7 - Input Output Statements in C++Chapter 7 - Input Output Statements in C++
Chapter 7 - Input Output Statements in C++
 
Exploiting vectorization with ISPC
Exploiting vectorization with ISPCExploiting vectorization with ISPC
Exploiting vectorization with ISPC
 
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingDynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
 
Go之道
Go之道Go之道
Go之道
 
Concurrency in Python4k
Concurrency in Python4kConcurrency in Python4k
Concurrency in Python4k
 
Number
NumberNumber
Number
 
Abstracting over Execution with Higher Kinded Types
Abstracting over Execution with Higher Kinded TypesAbstracting over Execution with Higher Kinded Types
Abstracting over Execution with Higher Kinded Types
 
Crystal Ball Event Prediction and Log Analysis with Hadoop MapReduce and Spark
Crystal Ball Event Prediction and Log Analysis with Hadoop MapReduce and SparkCrystal Ball Event Prediction and Log Analysis with Hadoop MapReduce and Spark
Crystal Ball Event Prediction and Log Analysis with Hadoop MapReduce and Spark
 
Labsheet_3
Labsheet_3Labsheet_3
Labsheet_3
 
Python programing
Python programingPython programing
Python programing
 
built in function
built in functionbuilt in function
built in function
 
Ch9c
Ch9cCh9c
Ch9c
 
GECon2017_Cpp a monster that no one likes but that will outlast them all _Ya...
GECon2017_Cpp  a monster that no one likes but that will outlast them all _Ya...GECon2017_Cpp  a monster that no one likes but that will outlast them all _Ya...
GECon2017_Cpp a monster that no one likes but that will outlast them all _Ya...
 
GECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them allGECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them all
 
Simulador carrera de caballos desarrollado en C++
Simulador carrera de caballos desarrollado en C++Simulador carrera de caballos desarrollado en C++
Simulador carrera de caballos desarrollado en C++
 
Introduction to graphics programming in c
Introduction to graphics programming in cIntroduction to graphics programming in c
Introduction to graphics programming in c
 
The Big Three
The Big ThreeThe Big Three
The Big Three
 
Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)
 
Garbage Collection
Garbage CollectionGarbage Collection
Garbage Collection
 
Probability of finding a single qubit in a state
Probability of finding a single qubit in a stateProbability of finding a single qubit in a state
Probability of finding a single qubit in a state
 

Ähnlich wie Computer hw1

Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]RootedCON
 
Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Tom Paulus
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchainedEduard Tomàs
 
Chapter Eight(3)
Chapter Eight(3)Chapter Eight(3)
Chapter Eight(3)bolovv
 
Maker All - Executive Presentation
Maker All - Executive PresentationMaker All - Executive Presentation
Maker All - Executive PresentationDiogoFalcao
 
Intel JIT Talk
Intel JIT TalkIntel JIT Talk
Intel JIT Talkiamdvander
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with PythonHan Lee
 
Functional Core and Imperative Shell - Game of Life Example - Haskell and Scala
Functional Core and Imperative Shell - Game of Life Example - Haskell and ScalaFunctional Core and Imperative Shell - Game of Life Example - Haskell and Scala
Functional Core and Imperative Shell - Game of Life Example - Haskell and ScalaPhilip Schwarz
 
Halide tutorial 2019
Halide tutorial 2019Halide tutorial 2019
Halide tutorial 2019Champ Yen
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)Saifur Rahman
 
Arduino coding class part ii
Arduino coding class part iiArduino coding class part ii
Arduino coding class part iiJonah Marrs
 
Building Interpreters with PyPy
Building Interpreters with PyPyBuilding Interpreters with PyPy
Building Interpreters with PyPyDaniel Neuhäuser
 
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019corehard_by
 
C Programming Training in Ambala ! Batra Computer Centre
C Programming Training in Ambala ! Batra Computer CentreC Programming Training in Ambala ! Batra Computer Centre
C Programming Training in Ambala ! Batra Computer Centrejatin batra
 
Coscup2021 - useful abstractions at rust and it's practical usage
Coscup2021 - useful abstractions at rust and it's practical usageCoscup2021 - useful abstractions at rust and it's practical usage
Coscup2021 - useful abstractions at rust and it's practical usageWayne Tsai
 
Circles graphic
Circles graphicCircles graphic
Circles graphicalldesign
 

Ähnlich wie Computer hw1 (20)

Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
 
Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchained
 
Chapter Eight(3)
Chapter Eight(3)Chapter Eight(3)
Chapter Eight(3)
 
Maker All - Executive Presentation
Maker All - Executive PresentationMaker All - Executive Presentation
Maker All - Executive Presentation
 
Intel JIT Talk
Intel JIT TalkIntel JIT Talk
Intel JIT Talk
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
 
Boosting Developer Productivity with Clang
Boosting Developer Productivity with ClangBoosting Developer Productivity with Clang
Boosting Developer Productivity with Clang
 
Functional Core and Imperative Shell - Game of Life Example - Haskell and Scala
Functional Core and Imperative Shell - Game of Life Example - Haskell and ScalaFunctional Core and Imperative Shell - Game of Life Example - Haskell and Scala
Functional Core and Imperative Shell - Game of Life Example - Haskell and Scala
 
Halide tutorial 2019
Halide tutorial 2019Halide tutorial 2019
Halide tutorial 2019
 
Seeing Like Software
Seeing Like SoftwareSeeing Like Software
Seeing Like Software
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)
 
Arduino coding class part ii
Arduino coding class part iiArduino coding class part ii
Arduino coding class part ii
 
Building Interpreters with PyPy
Building Interpreters with PyPyBuilding Interpreters with PyPy
Building Interpreters with PyPy
 
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
 
C Programming Training in Ambala ! Batra Computer Centre
C Programming Training in Ambala ! Batra Computer CentreC Programming Training in Ambala ! Batra Computer Centre
C Programming Training in Ambala ! Batra Computer Centre
 
Coscup2021 - useful abstractions at rust and it's practical usage
Coscup2021 - useful abstractions at rust and it's practical usageCoscup2021 - useful abstractions at rust and it's practical usage
Coscup2021 - useful abstractions at rust and it's practical usage
 
Vcs23
Vcs23Vcs23
Vcs23
 
Circles graphic
Circles graphicCircles graphic
Circles graphic
 
Mcq cpup
Mcq cpupMcq cpup
Mcq cpup
 

Computer hw1

  • 1. Computer Project for Chapter 1 1. (a) Obtain a set of YCrCb images for the set of 256x256 RGB Lena Images (Lena256C.bmp is a color input image) (b) Obtain a set of HIS images for the set of RGB images 2. Obtain images subsampled with (2:1)x(2:1), (4:1)x(4:1) from 512x512 Lena image. Display the original image and the subsampled ones with the same size and compare their qualities (Le512.raw is a gray input image). 3. Obtain 1-, 2-, 4-, 6-bit images from 8-bit 512x512 Lena image. Display the original image and the outputs, and compare their qualities (Le512.raw is a gray input image). Note: 1. Lena256C is a bitmap color image. You should read it out in your program using the following referenced function in C++, and then RGB images will be stored in * * * array for further processing ====== unsigned char*** ReadRGB(char *str, int &height, int &width, int &bit) { unsigned char ***rgb=NULL; FILE *fp; if((fp=fopen(str,"rb"))==NULL) { // AfxMessageBox("file open error"); return(rgb); } BITMAPFILEHEADER bmpfileheader; fread(&bmpfileheader,sizeof(BITMAPFILEHEADER),1,fp);
  • 2. BITMAPINFOHEADER bmpinfoheader; fread(&bmpinfoheader,sizeof(BITMAPINFOHEADER),1,fp); bit=bmpinfoheader.biBitCount; int byte_count=bit/8; height=bmpinfoheader.biHeight; width=bmpinfoheader.biWidth; if(bit!=24&&bit!=8) { // AfxMessageBox("No 8bit or 24bit image!."); fclose(fp); return(rgb); } rgb=(unsigned char***)malloc(byte_count*sizeof(unsigned char**)); for(int i=0;i<byte_count;i++) { rgb[i]=(unsigned char**)malloc(height*sizeof(unsigned char*)); for(int y=0;y<height;y++) rgb[i][y]=(unsigned char*)malloc(width); }
  • 3. for(int y=0;y<height;y++) for(int x=0;x<width;x++) { for(i=0;i<byte_count;i++) { rgb[byte_count-i-1][x][y]=getc(fp); } } fclose(fp); return(rgb); } ====== 2. Lena.raw is a 8-bit gray scale image. You may refer the following code: ====== float x[256][256], y[256][256]; //x array for in put, y array for output FILE *fo ,*fs ; int i,j; fo=fopen("lena.raw","rb");//for reading raw image for(i=0;i<256;i++) { for(j=0; j<256; j++) { x[i][j]=(float)getc(fo); } } fs=fopen("output.raw","wb");// for writing raw image for(i=0;i<256;i++) {
  • 4. for(j=0;j<256;j++) { putc((unsigned char)y[i][j],fs); } } }