We did it!

My buddy and I finally acomplish our project for our TC101 class.

Well, basically, our program had to do the following:

“You will create a command-line program that uses two-dimensional arrays or matrices to process images. You cannot simply call graphics libraries to manipulate the images directly but must implement the functions with your own algorithms. The input to each operation is an image (you choose to support any of JPEG, PNG) and the output is the modified image. The idea is to have a final project which shows your mastery of the topics in this course”.

I was really hard to acomplish but Eduardo and I worked together and we made it!

The user is able to type in the name of the file (a picture) and the program will process the image outputting a different file than the first one.

There is a huge code!

It looks like this:

#include <Magick++.h>
#include <iostream>
#include <cmath>
using namespace std;
using namespace Magick;

void grayscale (string in, string out){
  Image image;
  image.read( in );
  int x = image.rows();
  int y = image.columns();
  Color image_array [x] [y];
  Color original;
  Color graysc;
  int col;

  for (int i=0; i < x; i++){                    
    for (int u = 0; u < y; u++){               
      original = image.pixelColor(u,i); 
      image_array [i][u] = original;
      col = (original.redQuantum() + original.greenQuantum() + original.blueQuantum()) / 3;
      image_array [i] [u] = graysc;
      image.pixelColor(u, i, graysc);
  image.write( out );

void scale(string in, string out){
  Image image;
  image.read( in );

  int x = image.rows();
  int y = image.columns();
  int xf = x/2;
  int yf = y/2;
  Image image2( Geometry(yf, xf), Color(MaxRGB, MaxRGB, MaxRGB, 0));
  Color image_array [x] [y];
  Color image_array2 [xf] [yf];
  Color pixel1, pixel2, pixel3, pixel4, pixel5;
  int red,blue,green;
  Color newRGB, newRGB2;

  for (int i=0; i < x; i++){
        for (int u = 0; u < y; u++){
              pixel1 = image.pixelColor(u,i);
              image_array [i][u] = pixel1;

  for (int i=0; i < x; i = i+2){
       for (int u = 0; u < y; u = u+2){
       	     int x2 = i/2;
       	     int y2 = u/2;
             pixel2 = image_array [i] [u];
             pixel3 = image_array [i+1] [u];
             pixel4 = image_array [i] [u+1];
             pixel5 = image_array [i+1] [u+1];
             red = (pixel2.redQuantum() + pixel3.redQuantum() + pixel4.redQuantum() + pixel5.redQuantum())/4;
             blue = (pixel2.blueQuantum() + pixel3.blueQuantum() + pixel4.blueQuantum() + pixel5.blueQuantum())/4;
             green = (pixel2.greenQuantum() + pixel3.greenQuantum() + pixel4.greenQuantum() + pixel5.greenQuantum())/4;
             image_array2 [x2] [y2] = newRGB;

  for (int i=0; i < xf; i++){
       for (int u = 0; u < yf; u++){
             newRGB2 =image_array2 [i] [u];
             image2.pixelColor(u, i, newRGB2);

 image2.write( out );

int main(int argc,char **argv)

  try {
 string im;
 string out;
 int ans;
 cout << "Write your file name: ";
 cin >> im;
 cout<< "Write the name of your output file: ";
 cout<<"What do you wanna do?"<<endl<<"1. Grayscale."<<endl<<"2. Scale (1/2)."<<endl;

while (ans != 1 && ans != 2){
  cout<<"Try again please: ";
if(ans == 1){
 grayscale(im, out);}
 if (ans == 2){
 scale(im, out);
  catch( Exception &error_ )
      cout << "Caught exception: " << error_.what() << endl;
      return 1;
  return 0;
//// c++ -O2 -o prog prog.cpp `Magick++-config --cppflags --cxxflags --ldflags --libs`


There is also a Repository made it in Github and that’s were our teacher is going to check it out.

Any question feel completely free to ask.

Thank you guys for everything.

-The Admin.



CC BY 4.0 Final Project! by esaupreciado is licensed under a Creative Commons Attribution 4.0 International License.