#include "correlation.h" #include "iScissor.h" // two inlined routined that may help; inline Node &NODE(Node *n, int i, int j, int width) { return *(n+j*width+i); } inline unsigned char PIXEL(const unsigned char *p, int i, int j, int c, int width) { return *(p+3*(j*width+i)+c); } /************************TO DO 1*************************** *InitNodeBuf * INPUT: * img: a RGB image of size imgWidth by imgHeight; * nodes: an allocated buffer of Nodes of the same size, one node corresponds to a pixel in img; * OUPUT: * initializes the column, row, and linkCost fields of each node in the node buffer. */ void InitNodeBuf(Node *nodes, const unsigned char *img, int imgWidth, int imgHeight) { printf("InitNodeBuf in iScissor.cpp: to be implemented!\n"); } /************************TO DO 4*************************** *LiveWireDP: * INPUT: * seedX, seedY: seed position in nodes * nodes: node buffer of size width by height; * width, height: dimensions of the node buffer; * selection: if selection != NULL, search path only in the subset of nodes[j*width+i] if selection[j*width+i] = 1; * otherwise, search in the whole set of nodes. * numExpanded: compute the only the first numExpanded number of nodes; (for debugging) * OUTPUT: * computes the minimum path tree from the seed node, by assigning * the prevNode field of each node to its predecessor along the minimum * cost path from the seed to that node. */ void LiveWireDP(int seedX, int seedY, Node *nodes, int width, int height, const unsigned char *selection, int numExpanded) { printf("LiveWireDp in iScissor.cpp: to be implemented!\n"); } /************************TO DO 5*************************** *MinimumPath: * INPUT: * nodes: a node buffer of size width by height; * width, height: dimensions of the node buffer; * freePtX, freePtY: an input node position; * OUTPUT: * insert a list of nodes along the minimum cost path from the seed node to the input node. * Notice that the seed node in the buffer has a NULL predecessor. * And you want to insert pointer to Node in path, e.g., * insert nodes+j*width+i if you want to insert node at (i,j), instead of nodes[nodes+j*width+i]!!! * after the procedure, the seed should be the head of path and the input code should be the tail */ void MinimumPath(CTypedPtrDblList *path, int freePtX, int freePtY, Node *nodes, int width, int height) { printf("MinimumPath in iScissor.cpp: to be implemented!\n"); } /************************An Extra Credit*************************** *SeeSnap: * INPUT: * img: a RGB image buffer of size width by height; * width, height: dimensions of the image buffer; * x,y: an input seed position; * OUTPUT: * update the value of x,y to the closest edge based on local image information. */ void SeedSnap(int &x, int &y, unsigned char *img, int width, int height) { printf("SeedSnap in iScissor.cpp: to be implemented for extra credits!\n"); } //generate a cost graph from original image and node buffer with all the link costs; void MakeCostGraph(unsigned char *costGraph, const Node *nodes, const unsigned char *img, int imgWidth, int imgHeight) { int graphWidth = imgWidth * 3; int graphHeight = imgHeight * 3; int dgX = 3; int dgY = 3*graphWidth; int i,j; for (j=0;jlinkCost[0]); DigitizeCost(cst - dgY + dgX, node->linkCost[1]); DigitizeCost(cst - dgY , node->linkCost[2]); DigitizeCost(cst - dgY - dgX, node->linkCost[3]); DigitizeCost(cst - dgX, node->linkCost[4]); DigitizeCost(cst + dgY - dgX, node->linkCost[5]); DigitizeCost(cst + dgY , node->linkCost[6]); DigitizeCost(cst + dgY + dgX, node->linkCost[7]); } } }