Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please do this code in C programming language The code cellCount.c : #include #include #define IMAGE_SIZE 10 // this function prints the array void printImgArray(int

Please do this code in C programming language

image text in transcribedimage text in transcribedimage text in transcribed

The code cellCount.c :

#include

#include

#define IMAGE_SIZE 10

// this function prints the array

void printImgArray(int array[IMAGE_SIZE][IMAGE_SIZE])

{

printf("------ Image Contents ------- ");

for (int i=0; i

{

for (int j=0; j

printf("%02d, ",array[i][j]);

printf(" ");

}

printf("----------------------------- ");

}

/**

* This function counts the number of distinct

* number (i.e. the number of cells)

**/

int cellCount(int image[IMAGE_SIZE][IMAGE_SIZE]){

// insert your code for task1.1 here

// you may want to change the return value.

return 0;

}

/**

* This function colors each cell with a unique color

* (i.e. unique number)

**/

void color(int image[IMAGE_SIZE][IMAGE_SIZE]){

// insert your code for task 1.2 here

}

/**

* This function colors each cell with a unique color

* (i.e., unique number). This function works with

* pointers

* currentRow: shows the current row that is processed

* currentCol: shows the current column that is process

* currentIndex: show the index that is processed

* color: is an integer that represents a color

**/

int colorRecursively(int image[IMAGE_SIZE][IMAGE_SIZE], int currentRow, int currentCol, int currentIndex, int color) {

// insert your code for task 2.1 here, in case you decided to complete this task

// you may want to change the return value

return 0;

}

void colorPtr(int* image){

// insert your code for task 2.2 here

}

#ifndef __testing

int main(){

// DO not change anything in main(), it will confuse the

// auto-checker.

puts("testing the code with color() function");

int count = 0;

int cellImg[IMAGE_SIZE][IMAGE_SIZE]={{0,0,1,1,0,0,1,0,0,1},\

{1,0,1,1,0,0,1,1,0,1},\

{1,0,0,1,1,0,1,1,0,1},\

{1,1,0,0,0,0,0,0,0,0},\

{1,0,0,1,1,1,0,0,1,0},\

{0,0,0,0,1,0,0,1,1,0},\

{0,0,1,0,0,1,0,1,0,0},\

{0,0,1,1,0,0,1,0,0,0},\

{0,0,1,0,0,0,0,0,1,1},

{0,1,1,0,0,0,1,1,1,1}};

printImgArray(cellImg);

color(cellImg);

printImgArray(cellImg);

count=cellCount(cellImg);

printf("Total number of cells in the image: %d ",count);

puts("Testing the code with colorPtr");

int cellImg_[IMAGE_SIZE][IMAGE_SIZE]={{0,0,1,1,0,0,1,0,0,1},\

{1,0,1,1,0,0,1,1,0,1},\

{1,0,0,1,1,0,1,1,0,1},\

{1,1,0,0,0,0,0,0,0,0},\

{1,0,0,1,1,1,0,0,1,0},\

{0,0,0,0,1,0,0,1,1,0},\

{0,0,1,0,0,1,0,1,0,0},\

{0,0,1,1,0,0,1,0,0,0},\

{0,0,1,0,0,0,0,0,1,1},

{0,1,1,0,0,0,1,1,1,1}};

int* ptr = cellImg_;

printImgArray(ptr);

colorPtr(ptr);

printImgArray(ptr);

count=cellCount(ptr);

printf("Total number of cells in the image: %d ",count);

puts("Testing the code with colorRecursively");

int cellImg__[IMAGE_SIZE][IMAGE_SIZE]={{0,0,1,1,0,0,1,0,0,1},\

{1,0,1,1,0,0,1,1,0,1},\

{1,0,0,1,1,0,1,1,0,1},\

{1,1,0,0,0,0,0,0,0,0},\

{1,0,0,1,1,1,0,0,1,0},\

{0,0,0,0,1,0,0,1,1,0},\

{0,0,1,0,0,1,0,1,0,0},\

{0,0,1,1,0,0,1,0,0,0},\

{0,0,1,0,0,0,0,0,1,1},

{0,1,1,0,0,0,1,1,1,1}};

printImgArray(cellImg__);

colorRecursively(cellImg__, 0, 0, 1, 0);

printImgArray(cellImg__);

count=cellCount(cellImg__);

printf("Total number of cells in the image: %d ",count);

return 0;

}

#endif

Problem Description: In order to count a number of blood cells in a sample, a blood cell slide is created and looked at through a microscope's lens. To get a clear understanding of what a blood cell slide looks like, please see the picture below was borrowed We were able to write a code the reads this image and convert it to a two-dimensional array, where the blood cells in red are represented with 1 and the rest is represented with zero. Then we got a small sample of this two-dimensional array for which we need to write a code that counts the number of blood cells. A blood cell is a group of 1s that are connected horizontally, vertically, or diagonally. Task 1: For this task, you are going to complete two functions. One to label each cell with a unique number and another to count the number of the unique cells. 1. The first function gets a 10x10 two-dimensional array and return the number of distinct cells. This array represents each unique cell with a unique number. Please see the right picture below in which you can see there are 7 distinct cells, each represented with a unique number. If the right picture below is sent to this function, it should return 7, as there are 7 distinct groups of data. The signature of this function is as follow: int cellCount (int image (IMAGE_SIZE] [IMAGE_SIZE]); 2. The second function labels each cell with a unique number. For example, if the given image (i.e., two-dimensional array) is something like the left picture below, one sample solution can be something like the right picture. It is not important how you choose the numbers for the cell, as long as it is not zero or a negative number. Also, the numbers do not need to be in a consecutive order. For example, one might label the cells in the example below with arbitrary numbers of 20, 3, 4, 8, 18, 7, 1. The signature of this function looks like below: void color (int image (IMAGE_SIZE] [IMAGE_SIZE]); This function gets the 10x10 two-dimensional array (like the left picture) and label each group of 1s (a distinct cell) with a unique number (like the right picture). 0 0 1 1 0 0 1 0 0 1 1 0 1 1 0 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 11 1 0 0 1 1 1 0 0 1 0 0000100110 0 0 1 0 0 1 0 1 0 0 0 0 1 1 0 0 1000 0 0 1 0 0 0 0 0 1 1 0 1 1 0 0 0 1 1 1 1 00 2200 30 0 4 1 0 2 2 0 0 3 3 0 4 10 0 2 2 0 3 3 0 4 1100000000 10 0 5 5 5 0 0 5 0 0000 500 550 0 0 6 0 0 5 0 5 0 0 0 0 6 600 5000 00600000 77 0 0 0 6 6 0 To solve this problem, you are free to define as many helper functions as required. To test your code, we only look at the return value and the content of the array, expecting that each blood cell is labeled with a unique number. Task2: For this task, you have an option to choose from the given two tasks 2.1 or 2.2. Choose the one that you are more comfortable with and complete the task. Task 2.1: For this task I ask you to redesign the color() function and implement it using recursion. The function signature is: int colorRecursively(int image [IMAGE_SIZE] [IMAGE_SIZE], int currentRow , int currentCol, int current Index, int toIndex) Task 2.2: For this task I'd like you to re-implement function color (), where the input parameter is defined as a pointer. For this, you require to use pointer arithmetic instead of using array indices to get access to the elements of the array. The function signature is: void colorPtr(int* image); Hint: You have already learned in the lecture as to how get access to the element of the arrays using a pointer. So if ptr, is pointer that holds the address of the first element of your array (.e. int* ptr &array[0]), then ptr+1, ptr+2, ...ptr+i points to the second, third and i+1 element of the array. If ptr points to a first element of two-dimensionals array (i.e. int* ptr & array[0][0]) and the array has n columns then array[i][j] can be accessed via * (array+ (i * n) + j). Suppose you define the array as int array[4] [3]. Int this case n 3, therefore array+ (i * 3) + j will give you the address of the elements at index [i][j]. The memory that is assigned to this array looks like below: Memory Address 100 101 102 103 104 105 106 107 108 109 110 111 Array's Elements a (0][0] a[0][1] a[0][2] a [1][0] a[1][1] a[1][2] a (2][0] a[2][1] a[2][2] a [3][0] a[3][1] a[3] [2] Problem Description: In order to count a number of blood cells in a sample, a blood cell slide is created and looked at through a microscope's lens. To get a clear understanding of what a blood cell slide looks like, please see the picture below was borrowed We were able to write a code the reads this image and convert it to a two-dimensional array, where the blood cells in red are represented with 1 and the rest is represented with zero. Then we got a small sample of this two-dimensional array for which we need to write a code that counts the number of blood cells. A blood cell is a group of 1s that are connected horizontally, vertically, or diagonally. Task 1: For this task, you are going to complete two functions. One to label each cell with a unique number and another to count the number of the unique cells. 1. The first function gets a 10x10 two-dimensional array and return the number of distinct cells. This array represents each unique cell with a unique number. Please see the right picture below in which you can see there are 7 distinct cells, each represented with a unique number. If the right picture below is sent to this function, it should return 7, as there are 7 distinct groups of data. The signature of this function is as follow: int cellCount (int image (IMAGE_SIZE] [IMAGE_SIZE]); 2. The second function labels each cell with a unique number. For example, if the given image (i.e., two-dimensional array) is something like the left picture below, one sample solution can be something like the right picture. It is not important how you choose the numbers for the cell, as long as it is not zero or a negative number. Also, the numbers do not need to be in a consecutive order. For example, one might label the cells in the example below with arbitrary numbers of 20, 3, 4, 8, 18, 7, 1. The signature of this function looks like below: void color (int image (IMAGE_SIZE] [IMAGE_SIZE]); This function gets the 10x10 two-dimensional array (like the left picture) and label each group of 1s (a distinct cell) with a unique number (like the right picture). 0 0 1 1 0 0 1 0 0 1 1 0 1 1 0 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 11 1 0 0 1 1 1 0 0 1 0 0000100110 0 0 1 0 0 1 0 1 0 0 0 0 1 1 0 0 1000 0 0 1 0 0 0 0 0 1 1 0 1 1 0 0 0 1 1 1 1 00 2200 30 0 4 1 0 2 2 0 0 3 3 0 4 10 0 2 2 0 3 3 0 4 1100000000 10 0 5 5 5 0 0 5 0 0000 500 550 0 0 6 0 0 5 0 5 0 0 0 0 6 600 5000 00600000 77 0 0 0 6 6 0 To solve this problem, you are free to define as many helper functions as required. To test your code, we only look at the return value and the content of the array, expecting that each blood cell is labeled with a unique number. Task2: For this task, you have an option to choose from the given two tasks 2.1 or 2.2. Choose the one that you are more comfortable with and complete the task. Task 2.1: For this task I ask you to redesign the color() function and implement it using recursion. The function signature is: int colorRecursively(int image [IMAGE_SIZE] [IMAGE_SIZE], int currentRow , int currentCol, int current Index, int toIndex) Task 2.2: For this task I'd like you to re-implement function color (), where the input parameter is defined as a pointer. For this, you require to use pointer arithmetic instead of using array indices to get access to the elements of the array. The function signature is: void colorPtr(int* image); Hint: You have already learned in the lecture as to how get access to the element of the arrays using a pointer. So if ptr, is pointer that holds the address of the first element of your array (.e. int* ptr &array[0]), then ptr+1, ptr+2, ...ptr+i points to the second, third and i+1 element of the array. If ptr points to a first element of two-dimensionals array (i.e. int* ptr & array[0][0]) and the array has n columns then array[i][j] can be accessed via * (array+ (i * n) + j). Suppose you define the array as int array[4] [3]. Int this case n 3, therefore array+ (i * 3) + j will give you the address of the elements at index [i][j]. The memory that is assigned to this array looks like below: Memory Address 100 101 102 103 104 105 106 107 108 109 110 111 Array's Elements a (0][0] a[0][1] a[0][2] a [1][0] a[1][1] a[1][2] a (2][0] a[2][1] a[2][2] a [3][0] a[3][1] a[3] [2]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is the difference between an options price and its payoff?

Answered: 1 week ago

Question

Identify the five styles of handling conflict.

Answered: 1 week ago