Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write CPP Program for the below description? Define and initialize a 3D array to

ID: 3761801 • Letter: W

Question

Write CPP Program for the below description?

Define and initialize a 3D array to keep RGB pixels structured.

Read pixels from three different files into your 3D array (you read the data from file number-by-number).

Find average values for each layer R (red), G (green), B (blue) (Array[i][j][0] + Array[i][j][1]  + Array[i][j][2] ) /3, which is called intensity of a pixel. In the notation of Array[i][j][c], c is the color band, i anc j are location of the pixel.

Find maximum and minimum intensity pixels of the image. Also, print out those pixel addresses of min an max values. Intensity is average of R, G, and B values. In case of multiple minimum and maximum values, you should show all of the pixel locations.

List address (x, y location) of pixels meeting if pixel's Red value is less than pixel's Blue value.

Constrains: You need to read each source file just once.

Explanation / Answer

Answer:

The solution is provided for reading the values from the text files. Printing of the values of RGB pixels values and finding the minimum and maximum intensity of the pixels. Still require more information to solve the problem. If possible provide the sample text files and sample output.

Here is the program given below:

Program code:

// PixelsofRGB.cpp

//Header files.

#include "stdafx.h"

#include <iostream>

#include <fstream>

#include <string>

using namespace std;

int main()

{

     int RGB[3][3][3];

     double average[11], avg[3][3][1];

     double total = 0;

     ifstream red("RedPixelsInfo.txt");

     ifstream green("GreenPixelsInfo.txt");

     ifstream blue("BluePixelsInfo.txt");

     int i = 0, j = 0, c = 0;

     if(red && green && blue)

     {

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

          {

              for(j=0;j<10;j++)

              {

                   c=0;

                   red>>RGB[i][j][c];

                   c++;

                   green>>RGB[i][j][c];

                   c++;

                   blue>>RGB[i][j][c];

                   c++;

              }

          }

         

     }

     else if(!red)

     {

          cout<<"Unable to open the red pixels data file."<<endl;

     }

     else if(!green)

     {

          cout<<"Unable to open the green pixels data file."<<endl;

     }

     else if(!blue)

     {

          cout<<"Unable to open the blue pixels data file."<<endl;

     }

     else

     {

          cout<<"Unable to open all the three files."<<endl;

     }

     red.close();

     green.close();

     blue.close();

     int acount=0;

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

     {

          for(j=0;j<=3;j++)

          {

              total=0;

              for(c = 0; c < 3; c++)

              {

                   cout<<RGB[i][j][c]<<" ";

                   total+=RGB[i][j][c];

                   //avg[i][j]=total/3;

              }

                            

              avg[i][j][0]=total/3;

             

              cout<<" "<<avg[i][j][0]<<endl;                         

          }        

     }

     int size = acount;

     double min = avg[0][0][0], max=avg[0][0][0];

     acount = 0;

     //cout<<"count: "<<count<<endl;

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

     {

          for(j=0;j<3;j++)

          {

             

              if(avg[i][j][0]<min)

                   min = avg[i][j][0];

              if(avg[i][j][0]>max)

                   max=avg[i][j][0];                

          }        

     }

     cout<<endl;

     cout<<"The minimum intensity "<<min<<" is at location / s: "<<endl;

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

     {

          for(j=0;j<=3;j++)

          {            

              if(avg[i][j][0]==min)

                   cout<<"("<<(i+j)<<", "<<j<<")."<<endl;         

          }        

     }

     cout<<endl;

     cout<<"The maximum intensity "<<max<<" is at location / s: "<<endl;

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

     {

          for(j=0;j<=3;j++)

          {            

              if(avg[i][j][0]==max)

                   cout<<"("<<(i+j)<<", "<<j<<")."<<endl;         

          }        

     }

    

     system("pause");

     return 0;

}

Sample Output:

Sample output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote