Could someone help me with the c language below? The first page is the struct quad and the last page is the image file.

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Could someone help me with the c language below? The first page is the struct quad and the last page is the image file.

Post by answerhappygod »

Could someone help me with the c language below? The first page is the struct quad and the last page is the image file. Please implement all the functions between first and last pages thanks!
Could Someone Help Me With The C Language Below The First Page Is The Struct Quad And The Last Page Is The Image File 1
Could Someone Help Me With The C Language Below The First Page Is The Struct Quad And The Last Page Is The Image File 1 (65.21 KiB) Viewed 34 times
Could Someone Help Me With The C Language Below The First Page Is The Struct Quad And The Last Page Is The Image File 2
Could Someone Help Me With The C Language Below The First Page Is The Struct Quad And The Last Page Is The Image File 2 (72.76 KiB) Viewed 34 times
Could Someone Help Me With The C Language Below The First Page Is The Struct Quad And The Last Page Is The Image File 3
Could Someone Help Me With The C Language Below The First Page Is The Struct Quad And The Last Page Is The Image File 3 (62.33 KiB) Viewed 34 times
Could Someone Help Me With The C Language Below The First Page Is The Struct Quad And The Last Page Is The Image File 4
Could Someone Help Me With The C Language Below The First Page Is The Struct Quad And The Last Page Is The Image File 4 (62.93 KiB) Viewed 34 times
Could Someone Help Me With The C Language Below The First Page Is The Struct Quad And The Last Page Is The Image File 5
Could Someone Help Me With The C Language Below The First Page Is The Struct Quad And The Last Page Is The Image File 5 (75.49 KiB) Viewed 34 times
* This is the structure we are going to use to store each individual node of * the BST. Remember that each Quad corresponds to a rectangular area on the * image: (tx, ty) X | | int sx; h| typedef struct quad int tx, ty; int w; int h; W Quad key = tx+(ty*sx) | | -X (tx + w, ty + h) // The (x,y) coordinates of the top-left pixel in the quad // How many pixels wide the quad is // How many pixels high the quad is // Width of the original image, this is needed for the key. // This *MUST be the same for all nodes in the BST int key; // A unique identifier (remember we discussed BST nodes // should have unique keys to identify each node). The // key identifier here will be created as: struct quad *left; struct quad *right;| Quad; key = tx + (ty * sx) // This means that only one quad can start at a specific // pixel. int wsplit; // 1 if this quad is supposed to be split along the width | | | | | | // 0 if this quad is supposed to be split along the height /*ok * TODO: Complete the definition of the Quad struct */
int get_colour (Image *im, Quad *q) { * Given an image 'im' and a Quad 'q', get the colour we should be assigning * to the pixels that are in it, and return it. For the sake of this * assignment, we will say this is *average* colour of all the pixels in * the quad. } * The pixel data is stored in a one dimensional array called 'data' in the * image struct. Make sure you look at the definition of this to understand * how the image is stored. Remember that the pixel data is stored in * row-major order, so to get the colour for pixel (x,y) you will look at the * index * } * * of the array. * * TODO: Implement this function. You should not be getting any values outside the range of the pixels [0-255] if you have implemented this correctly. * * */ return 0; x + (y * sx) int similar (Image *im, Quad *q, int threshold) { /*** * Given an image 'im', check if the colours in the area corresponding to the * Quad 'q' are all similar. If not, we will have to split it. For the * purpose of this assigment, we say the colours in a Quad are similar if * * * * where maxCol and minCol are the maximum and minimum values respectively * of the pixel colours in the Quad. The threshold is a parameter. This * function should return a 0 if the pixels are not similar enough and the * Quad needs to be split, and 1 otherwise. maxCol - minCol <= threshold return 0; * TODO: Implement this function */
Quad *split_tree (Image *im, Quad *root, int threshold) { *This function traverses the BST, and for each existing Quad, checks if * the pixels in the quad are of a similarcolour using the similar() function * and the given threshold. If they are not, then the Quad needs to be split * into 2 Quads (which will hopefully have pixels that are more similar to * each other). * * To do this, first we need to decide in which direction we are going to * split the Quad. For this, we will use the 'wsplit'field. * - If wsplit = 1, then we split it along the width (ie, we will now have 2 quads with the same heightand half the width as the original one) * If wsplit = 0, then we split along the height. * * * * NOTE: We don't always want to split the Quads in the same direction every time this function is called, because then we could just end up with very thin and long/tall quads, which wouldn't be very helpful to what we are trying to do. So, we need to make sure that once we split a Quad, that we invert the value of the 'wsplit' variable in both the new nodes, so they split the other way. * * * * For example, if our Quad had the following values: * (tx:ty = 0:0 w = 512, h = 512, wsplit = 1) ---> A (0,0) X | | | | | | | A I | -X (512, 512) * this pixel is not IN the image, just
* * it would be split along the width, and the resulting two Quads * we would get would be as follows: (tx: ty = 0:0 (tx:ty = 256:0 (0,0) | | | | | I | | | w = 256, w = 256, B (256, 0) | I * this pixel is not IN the image, just represents the 'corner'. The bottom right pixel, as always, is (511,511) | h = 512, h = 512, wsplit = 0) ---> B wsplit 0) ---> C | = (512, 512) Note that we want to always split it in exactly half, but if the width/height is an odd number then round down. Further note that 'wsplit' on both of these has now been set to 0. If they were split again, the resulting Quads would have wsplit = 1. * * * Now, once you know how it needs to be split, carefully form these two * Quads, with the correct positions and sizes, and replace the the original * one with them. * *This function is crunchy - and if you don't think it through before you * start implementing it you'll run into all kinds of trouble. * * This is the problem solving exercise for A2, so don't look for people * on Piazza to give you answers, or tell you what to do, or verify you're * doing the right thing.
} } * TODO: Implement this function */ return NULL; void drawOutline (Image *im, Quad *root, unsigned char col) { /*ok * Given an image 'im' and a BST rooted at 'root', traverse through each quad * and draw an outline for it. The outline consists of the outermost pixels * of the Quad (ie, the top and bottom rows, and the leftmost and rightmost * columns). * } as before, depending on how many of them needed to be split. * Make sure that these outlines are of the input colour 'col' that is passed * in. The colour of the remaining pixels should not be changed. * TODO: Implement this function */ return; void save_Quad (Image *im, Quad *root) { /*ok * Given an image 'im' and a BST rooted at 'root', traverse through each * quad, and set all the pixels in the corresponding area to the expected * colour of the quad computed by your function get_colour (). * Make sure you index into the pixels array correctly and change the colour * in the image itself. * * TODO: Implement this function */ return;
#include #include #include typedef struct image { // The pixel data here is stored in row major order // an unsigned char simply stores numbers from 0-255, // you can treat it as an int otherwise, just make sure // you **don't** assign values <0 or > 255, or else you // will get unexpected results unsigned char *data; // Width and height of the image // We are working with square images here, so you can // safely assume the height and width will be the same int sx; int sy; } Image; Image *newImage(int sx, int sy) { Image *im; im = (Image *) calloc(1, sizeof (Image)); if (im != NULL) { im->SX = SX; im->sy = sy; im->data = (unsigned char *) calloc(im->sx * im->sy, sizeof(int)); if (im->data != NULL) { } memset(im->data, 255, sx* sy); return im; printf("Error: Unable to allocate memory for new image\n"); return (NULL); Image *copyImage (Image *src) { Image *im; im = if (im != NULL) { (Image *) calloc(1, sizeof (Image)); im->sx = src->sx; im->sy = src->sy; im->data = (unsigned char *) calloc(im->5x * im->sv. sizeof(int)):
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply