Question

Image proccessing in PROGRAMING C NO MAIN FUNCTION NEEDED! Color-Filter an image: 1. All pixels in...

Image proccessing in PROGRAMING C

NO MAIN FUNCTION NEEDED!

Color-Filter an image:

1. All pixels in the picture with color in the chosen range will be replaced with new color. The following shows the pseudo code for the color filter.

if (R in the range of [target_r - threshold, target_r + threshold]) and (G in the range of [target_g - threshold, target_g + threshold]) and (B in the range of [target_b - threshold, target_b + threshold])

R = replace_r ;

G = replace_g ;

B = replace_b ;

else keep the current color

Given: void ColorFilter(unsigned char R[WIDTH][HEIGHT], unsigned char G[WIDTH][HEIGHT], unsigned char B[WIDTH][HEIGHT], int target_r, int target_g, int target_b, int threshold, int replace_r, int replace_g, int replace_b);

2. To mirror an image vertically, the intensity values in vertical direction at the top should be reversed and copied to the bottom.

Given: /* mirror image vertically */ void VMirror(unsigned char R[WIDTH][HEIGHT], unsigned char G[WIDTH][HEIGHT], unsigned char B[WIDTH][HEIGHT]);

3. This operation will add borders to the current image. The border color and width (in pixels) of the borders are parameters given by the user. Within your implementation, you should define an aspect ratio of 16:9 for your horizontal to vertical border. This should make your horizontal border look thicker than the vertical one.

Given: void AddBorder(unsigned char R[WIDTH][HEIGHT], unsigned char G[WIDTH][HEIGHT], unsigned char B[WIDTH][HEIGHT], char color[SLEN], int border_width);

4.The edge detection works this way: the intensity value at each pixel is mapped to a new value, which is the sum of itself and its 8 neighbors with different parameters. Note the sum of all parameters is 0, which will result in a vary dark image where only the edges are detected are colored. The following shows an example of the filter and the applied pixel:

You need to define and implement a function to do this DIP. Note that you have to set the boundary for the newly generated pixel value, i.e., the value should be within the range of [0,255]. Hint (the following code can be used to handle pixel intensity under- or overflow): if (v<0) v=0; else if (v>255) v=255;

Given: void Edge(unsigned char R[WIDTH][HEIGHT], unsigned char G[WIDTH][HEIGHT], unsigned char B[WIDTH][HEIGHT]);

0 0
Add a comment Improve this question Transcribed image text
Answer #1


1) color filter
#define filterWidth 3
#define filterHeight 3

double filter[filterHeight][filterWidth] =
{
0, 0, 0,
0, 1, 0,
0, 0, 0
};

double factor = 1.0;
double bias = 0.0;

int main(int argc, char *argv[])
{
//load the image into the buffer
unsigned long w = 0, h = 0;
std::vector<ColorRGB> image;
loadImage(image, w, h, "pics/photo3.png");
std::vector<ColorRGB> result(image.size());

//set up the screen
screen(w, h, 0, "Filters");

ColorRGB color; //the color for the pixels

//apply the filter
for(int x = 0; x < w; x++)
for(int y = 0; y < h; y++)
{
double red = 0.0, green = 0.0, blue = 0.0;

//multiply every value of the filter with corresponding image pixel
for(int filterY = 0; filterY < filterHeight; filterY++)
for(int filterX = 0; filterX < filterWidth; filterX++)
{
int imageX = (x - filterWidth / 2 + filterX + w) % w;
int imageY = (y - filterHeight / 2 + filterY + h) % h;
red += image[imageY * w + imageX].r * filter[filterY][filterX];
green += image[imageY * w + imageX].g * filter[filterY][filterX];
blue += image[imageY * w + imageX].b * filter[filterY][filterX];
}

//truncate values smaller than zero and larger than 255
result[y * w + x].r = min(max(int(factor * red + bias), 0), 255);
result[y * w + x].g = min(max(int(factor * green + bias), 0), 255);
result[y * w + x].b = min(max(int(factor * blue + bias), 0), 255);
}

//draw the result buffer to the screen
for(int y = 0; y < h; y++)
for(int x = 0; x < w; x++)
{
pset(x, y, result[y * w + x]);
}

//redraw & sleep
redraw();
sleep();
}

2) mirror image
BOOL BMPFile::VertFlipBuf(unsigned char * inbuf,
                   UINT widthBytes,
                   __int16 height)
{   
   BYTE *tb1;
   BYTE *tb2;

   if (inbuf==NULL)
       return FALSE;

   UINT bufsize;

   bufsize=widthBytes;

   tb1= new unsigned char[bufsize];
   if (tb1==NULL) {
       return FALSE;
   }

   tb2= new unsigned char [bufsize];
   if (tb2==NULL) {
       delete [] tb1;
       return FALSE;
   }
  
   __int16 row_cnt;   
   ULONG off1=0;
   ULONG off2=0;

   for (row_cnt=0;row_cnt<(height+1)/2;row_cnt++)
   {
       off1=row_cnt*bufsize;
       off2=((height-1)-row_cnt)*bufsize;
      
       memcpy(tb1,inbuf+off1,bufsize*sizeof(unsigned char));  
       memcpy(tb2,inbuf+off2,bufsize*sizeof(unsigned char));  
       memcpy(inbuf+off1,tb2,bufsize*sizeof(unsigned char));
       memcpy(inbuf+off2,tb1,bufsize*sizeof(unsigned char));
   }  

   delete [] tb1;
   delete [] tb2;

   return TRUE;
}

3) putting boder

HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
COORD CursorPosition;

void gotoXY(int x, int y);
void gotoXY(int x, int y, string text);
void Draw(int style, int col, int row, int length,int amount, bool filled, int shadow );

int main(int)
{
        //           Draw routine
        //  first number = 1 for single line, 2 for a double lines
        // second number = column's across
        //  third number = row's down
        // fourth number = box total length
        //  fifth number = box total height
        //  sixth number = 0 for not filled, 1 for filled 
        //seventh number = 0 for no shadow, 1 for a light shadow, 2 for medium shadow, 3 for a dark shadow and 4 for a solid shadow.

        string PressKey = "- Programmed by whitenite1 - Added flashing box frame on September 14th, 2011 - Press any key to end program...";
        int x, y, len, frame;
        y = 1;
        frame = 2;
        char holder;
        Draw(1,2,1,76,23,0,0);  // Box, 1 line, around screen
        Draw(2,12,4,56,16,1,4); // Box, 2 lines, around screen
        Draw(1,28,6,25,3,0,2);  // Box, 1 line,  for Title
        gotoXY(30,7,"Scrolling Text Demo 2");
        Draw(2,23,13,36,3,0,2); // Box for moving text
        len = PressKey.length();
        do
        {
                gotoXY( 25,14);
                for (x=0;x<32;x++)
                        cout << PressKey[x];  // scrolling the string called PressKey
                holder = PressKey[0];
                for ( x=0;x<len;x++)
                        PressKey[x] = PressKey[x+1];
                PressKey[len] = holder;
                Sleep(120);
                Draw(frame,23,13,36,3,0,0);
                y++;
                if (y>5)
                {
                        Draw(frame,28,6,25,3,0,0);
                        frame--;
                        y=0;
                }
                if ( frame==0)
                        frame=+2;
        } while (_kbhit() == '\0' );
        gotoXY(25,14,"            Good-Bye            ");
        gotoXY(25,14);
        Sleep(2500);
        return 0;
}

void gotoXY(int x, int y) 
{ 
        CursorPosition.X = x; 
        CursorPosition.Y = y; 
        SetConsoleCursorPosition(console,CursorPosition); 
}

void gotoXY(int x, int y, string text) 
{ 
        CursorPosition.X = x; 
        CursorPosition.Y = y; 
        SetConsoleCursorPosition(console,CursorPosition);
        cout << text;
}

void Draw(int style, int col, int row, int length,int amount, bool fill, int sw )
{
        // Draws a 1 or 2 line box 
        int a;
        if ( sw >4)
                sw = 4;
        style=(style-1)*6;
        char box[12];
        char shdw[5];
        
        box[0] = '\xDA';//  ┌
        box[1] = '\xBF';//  ┐
        box[2] = '\xC0';//  └
        box[3] = '\xD9';//  ┘
        box[4] = '\xB3';//  │ 
        box[5] = '\xC4';//  ─
        box[6] = '\xC9';//  ╔ 
        box[7] = '\xBB';//  ╗
        box[8] = '\xC8';//  ╚
        box[9] = '\xBC';//  ╝
        box[10] = '\xBA';// ║
        box[11] = '\xCD';// ═
        shdw[1] = '\xB0';// ░
        shdw[2] = '\xB1';// ▒
        shdw[3] = '\xB2';// ▓
        shdw[4] = '\xDB';// █
        char tl,tr,bl,br,side,edge,shadow;
        tl = box[style];
        tr = box[style+1];
        bl = box[style+2];
        br = box[style+3];
        side = box[style+4];
        edge = box[style+5];
        shadow = shdw[sw];
        string Line(length-2,edge);
        string Shadow(length,shadow);
        string Fill(length-2, ' ');
        gotoXY(col,row);
        cout << tl << Line << tr;
        for (a = 1; a <amount-1;a++)
        {
                gotoXY(col,row+a);
                        cout << side;
                if  (fill)
                        cout << Fill;
                else            
                        gotoXY(col+length-1,row+a);
                cout << side;
                if (sw)
                        cout << shadow;
        }
        gotoXY(col,(amount+row)-1);
        cout << bl << Line << br;
        if (sw)
        {
                cout << shadow;
                gotoXY(col+1,row+amount , Shadow );
        }
}

Edit & Run

  

Add a comment
Know the answer?
Add Answer to:
Image proccessing in PROGRAMING C NO MAIN FUNCTION NEEDED! Color-Filter an image: 1. All pixels in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 4. Write a function extract(pixels, rmin, rmax, cmin, cmax) that takes the 2-D list pixels contai...

    Please design the function in version 3 of python 4. Write a function extract(pixels, rmin, rmax, cmin, cmax) that takes the 2-D list pixels containing pixels for an image, and that creates and returns a new 2-D list that represents the portion of the original image that is specified by the other four parameters. The extracted portion of the image should consist of the pixels that fall in the intersection of the rows of pixels that begin with row rmin...

  • from PIL import Image import random # NOTE: Feel free to add in any constant values...

    from PIL import Image import random # NOTE: Feel free to add in any constant values you find useful to use BLACK = (0, 0, 0) WHITE = (255, 255, 255) # NOTE: Feel free to add in any helper functions to organize your code but # do NOT rename any existing functions (or else, autograder # won't be able to find them!!) # NOTE: The following function is already completed for you as an example # You can use...

  • WRITE A C++ PROGRAM TO ANSWER THE QUESTIONS BELOW. You are provided with an image in...

    WRITE A C++ PROGRAM TO ANSWER THE QUESTIONS BELOW. You are provided with an image in a new file format called JBC Here is an example of the format: 2 3 100 50 40 200 66 56 12 45 65 23 67 210 0 255 100 45 32 123 The first line means that this is a 2 (width) by 3 (height) image of pixels. Then, each line represents the color of a pixel. The numbers are from 0 to...

  • Your program should be capable of creating a ppm image of the flag of Benin • The new flag gener...

    Your program should be capable of creating a ppm image of the flag of Benin • The new flag generated should use the proper width-to-height ratio as defined on Wikipedia for the flag. o For the colors, use pure red, and yellow, and a value of 170 for green. ▪ Pure color values are talked about in Lab 6. o The left green field should be 6/15ths of the width of the flag. Variables country_code should also include a new...

  • I want to create the flags for Poland, the Netherlands, and Italy using ppm files and...

    I want to create the flags for Poland, the Netherlands, and Italy using ppm files and file redirection. I can't seem to get my pixels lined up correctly to make my flags. Here's my output for when I tried to make my flag for Poland. Any way to fix this? I am working in C #include #include <stdio.h> <stdlib.h> void make_pixel (int r, int g, int b); void make-ppm-header (int width, int height); void make_ppm_image (int country_code, int width) int...

  • Problem1: BMPmain.c, BMPfns.c, BMPfns.h, Makefile The file 'BMPmain.c' contains a main() function which is already written...

    Problem1: BMPmain.c, BMPfns.c, BMPfns.h, Makefile The file 'BMPmain.c' contains a main() function which is already written for you and attached with this homework. When appropriate functions are provided, main() will create a .bmp image file. Your job is to write 'BMPfns.c' which contains the functions which main() uses to create .bmp image files. You must also write the header file 'BMPfns.h' to #include in BMPmain.c and which contains prototypes of the functions defined in BMPfns.c . Problem2: BMPcheckerboard.c, BMPfns.c, BMPfns.h,...

  • the following python code edits BMP image file to negative but I need help with modifying...

    the following python code edits BMP image file to negative but I need help with modifying this code so it turns it the same BMP image file into a black and white instead of a negative. heres python code I have so far [pasted below] ## # This program processes a digital image by creating a negative of a BMP image. # from io import SEEK_CUR from sys import exit def main() : filename = input("Please enter the file name:...

  • Assignment Λ You shall write a Java program that accepts 5 command-line arguments and generates an image of a Sierpinski triangle, as a 24- bit RGB PNG image file. Specifications The command-line arg...

    Assignment Λ You shall write a Java program that accepts 5 command-line arguments and generates an image of a Sierpinski triangle, as a 24- bit RGB PNG image file. Specifications The command-line arguments shall consist of the following 1. The width (in pixels) of the image, as a positive decimal integer 2. The height (in pixels) of the image, as a positive decimal integer 3. The minimum area (in pixels) that a triangle must have in order to be drawn,...

  • use MATLAB to upload the following: an image that you want to process (can be taken...

    use MATLAB to upload the following: an image that you want to process (can be taken yourself or downloaded from the internet) a script that processes the image in TWO ways. manipulates the colors averages pixels together Please make sure the script displays the images (like how I did with the 40 and 80 pixel averaging) so I can easily compare them to the original. Make sure to COMMENT your code as well. Homework 13 Please upload the following: an...

  • Modify the NervousShapes program so that it displays equilateral triangles as well as circles and rectangles....

    Modify the NervousShapes program so that it displays equilateral triangles as well as circles and rectangles. You will need to define a Triangle class containing a single instance variable, representing the length of one of the triangle’s sides. Have the program create circles, rectangles, and triangles with equal probability. Circle and Rectangle is done, please comment on your methods so i can understand */ package NervousShapes; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import javax.swing.*; import javax.swing.event.*; public class...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT