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

Please complete this Edge Detection assignment. Use the code template provided b

ID: 3745481 • Letter: P

Question

Please complete this Edge Detection assignment. Use the code template provided below. Write your code where it says /* your code goes here */

This assignment explores the function and implementation of several basic conditional execution, iteration, and memory access mechanisms to implement a basic edge detection algorithm on an image. Background: Edge detection is a common technique used in many image processing applications to help delineate entities of interest, such as obstacles along a planned path or cell walls in a microscope slide image. One technique for edge detection examines each pixel and compares its intensity with its nearest neighbors (i.e., the four pixels to the North, South, East, and West). It finds maximum and minimum values (MaxI, Minl) of these data and and an output image is created in which each pixel is given the difference between the max and min (Maxi MinI) as its new intensity value. For this assignment, each input 32x32 image is given as an array of 1024 integers, each integer indicating an intensity value. (This array has been previously derived from a color image by taking the average of each pixel's red, green, and blue (RGB) color component intensities.) Pixels on the boundaries of the image must be handled specially to prevent trying to acces neighboring pixels that do not exist (i.e., no image wraparound is allowed. For example, if a pixel is on the top edge of the image, it will not have a northern neighbor, so its intensity wil only be compared with those of the other three neighbors. For this assignment, you will write two programs, one in C and one in MIPS, as described below. HW2-1: In this part of the assignment, design and implement a C program that computes the modified second image where pixels are replaced with the difference of the max and min intensity of the pixel and its neighbors. As a starting point, use the file HW2-1-shell.c. This program includes a reader function Load_Mem that loads the the pixel data from a text file into an array. You should use gcc under Linux/Unix to develop your program. Sample test files (Inputn.txt) are provided, along with corresponding Answern.txt files that contain the expected correct output data. You must copy/rename Hw2-1-shell.c to Hw2-1.c and modify it. The included print statement should be used to print all pixel values following the conclusion of your transformation. Its output format should not be modified.

Explanation / Answer

Please check the program, I dont have input so cant check it but I hope it works right.

#include<stdio.h>
#include<stdlib.h>

int RunningCount;

void CountHi(int);

int Load_Mem(char*,int[]);
int min(int a,int b);
int max(int a, int b);
int main(int argc, char *argv[]){
int Array[1024];
int Edges[1024];
int NumX;
int N;
int i,j; // loopers

if(argc!=2){
    printf("Usage: ./HW2-1 valuefile ");
    exit(1);
}

NumX = Load_Mem(argv[1],Array);
if(NumX != 1024){
    printf("valuefiles must contain 1024 entries ");
    exit(1);
}

RunningCount = 0;
for(N= 0; N<NumX;N++){
    Edges[N] =Array[N];
    CountHi(Array[N]);
    printf("%4d: %8d ",N,Edges[N]);
}

//this is the edge detection part
// assume the 1024 array is a 2d array with 32 rows and 32 cols
//then we can access by using i,j where i stands for row and j for column, is == i*32+j.
for(i =0;i<32;i++){
    for(j=0;j<32;j++){
      if(i==0) { //
   if(j == 0) {
      Edges[i*32+j] = max(Array[(i+1)*32 +j],Array[i*32+j+1]) - min(Array[(i+1)*32 +j],Array[i*32+j+1]);
   }
   else if(j == 31) {
      Edges[i*32+j] = max(Array[(i+1)*32 +j],Array[i*32+j-1]) - min(Array[(i+1)*32 +j],Array[i*32+j-1]);
   }
   else{
      Edges[i*32+j] = max(Array[(i+1)*32 +j],max(Array[i*32+j-1],Array[i*32+j+1])) - min(Array[(i+1)*32 +j],min(Array[i*32+j-1],Array[i*32+j+1]));
   }
      }
      else if(i == 31){
   if(j == 0) {
      Edges[i*32+j] = max(Array[(i-1)*32+j],Array[i*32+j+1]) - min(Array[(i-1)*32+j],Array[i*32+j+1]);
   }
   if(j == 31) {
      Edges[i*32+j] = max(Array[(i-1)*32+j],Array[i*32+j-1]) - min(Array[(i-1)*32+j],Array[i*32+j-1]);
   }
   else{
      Edges[i*32+j] = max(Array[(i-1)*32+j],max(Array[i*32+j-1],Array[i*32+j+1])) - min(Array[(i-1)*32+j],min(Array[i*32+j-1],Array[i*32+j+1]));
   }
      }
      else{
   Edges[i*32+j] = max(max(Array[(i+1)*32 +j],Array[(i-1)*32+j]),max(Array[i*32+j-1],Array[i*32+j+1])) - min(min(Array[(i+1)*32 +j],Array[(i-1)*32+j]),min(Array[i*32+j-1],Array[i*32+j+1]));
      }
    }
}
exit(0);
}

void CountHi(int Pixel){
if(Pixel >=200){
    RunningCount++;
}
    return ;
}


int Load_Mem(char* InputFileName,int IntArray[]){
    int N,Addr, Value, NumVals;
    FILE *FP;
    FP = fopen(InputFileName,"r");

    if(FP == NULL){

      printf("%s Could not be opend, check the filename ",InputFileName);
      return 0;
    }
    else{
      for(N=0;N<1024;N++){
   NumVals = fscanf(FP,"%d: %d", &Addr,&Value);
   if(NumVals == 2)
      IntArray[N] = Value;
   else
      break;
      }
      fclose(FP);
      return N;
    }
}

int min(int a,int b){
    if (a>b){
      return b;
    }
    else {
      return a;
    }
}

int max(int a, int b){
    if(a< b){
      return b;
    }
    else{
      return a;
    }
}

Happy Chegging!

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