int main(int argc, char** argv){ if(argc < 3){ std::cout << "usage:"<<std::endl; std::cout << "composite [foregroundImagename] [backgroundImagename]" << std::endl; std::cout << "or" <<std::endl; std::cout << "composite [foregroundImagename] [backgroundImagename] [outputIMagename]" << std::endl; exit(-1); } FileIO::getInstance().readFromFileToImage(foreImage, argv[1]); FileIO::getInstance().readFromFileToImage(backImage, argv[2]); imageToBeOutput = foreImage.over(backImage,0,0); display_data = new GLubyte[imageToBeOutput.getWidth()*imageToBeOutput.getHeight()*4]; imageToBeOutput.displayOutput(display_data); if(argc>3){ FileIO::getInstance().writeImageToFile(imageToBeOutput,argv[3]); } glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA); glutInitWindowSize(imageToBeOutput.getWidth(), imageToBeOutput.getHeight()); glutInitWindowPosition(0, 0); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutMainLoop(); return 0; }
//callback in glut loop void display(void) { std::cout << imageToBeOutput.getWidth() << " " << imageToBeOutput.getHeight() << " " << imageToBeOutput.getChannels()<<std::endl; glClear(GL_COLOR_BUFFER_BIT); glDrawPixels(imageToBeOutput.getWidth(), imageToBeOutput.getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, display_data); glFlush(); }
bool compareImage_basic(const MyImage &img_logo, const MyImage &img_pic) { int *his_logo = getHistogram_H(img_logo, 0, 0, img_logo.getHeight(), img_logo.getWidth()); int *his_pic = getHistogram_H(img_pic, 0, 0, img_pic.getHeight(), img_pic.getWidth()); print_arr(his_logo, H_N); print_arr(his_pic, H_N); int total_pixel = img_logo.getWidth() * img_logo.getHeight(); retainMajority(his_logo, 0.9, H_N); TRACE("After retaining majority\n"); print_arr(his_logo, H_N); filter(his_logo, his_pic, H_N); TRACE("After filtering\n"); print_arr(his_pic, H_N); double *norm_his_logo = normalize(his_logo, H_N); double *norm_his_pic = normalize(his_pic, H_N); double diff = differ(norm_his_logo, norm_his_pic, H_N); TRACE("ecu diff: %lf\n", diff); delete his_logo; delete his_pic; delete norm_his_logo; delete norm_his_pic; return diff <= THRESHOLD; }
void sendDecodeSequentialMode(void* storage){ TwoByte* st = (TwoByte*) storage; int h = workingImage.getHeight(); int w = workingImage.getWidth(); Byte* imgd = workingImage.getImageData(); unsigned int q = 1<<quantizationLevel; TwoByte* tblock = new TwoByte[192]; Byte* idctblock = new Byte[192]; for(int y = 0; y < h; y+=8){ for(int x = 0; x < w; x+=8){ for(int yy= 0; yy < 8; yy++){ for(int xx = 0; xx < 8; xx++){ int src = ((y + yy)*w + (x + xx))*3; int dest = (yy*8 + xx)*3; tblock[dest] = st[src]*q; tblock[dest + 1] = st[src + 1]*q; tblock[dest + 2] = st[src + 2]*q; } } doIDCT(tblock, idctblock); for(int yy= 0; yy < 8; yy++){ for(int xx = 0; xx < 8; xx++){ int dest = ((y + yy)*w + (x + xx))*3; int src = (yy*8 + xx)*3; imgd[dest] = idctblock[src]; imgd[dest + 1] = idctblock[src + 1]; imgd[dest + 2] = idctblock[src + 2]; } } drawImage(&workingImage, nextStart); Sleep(latency); } } delete[] tblock; delete[] idctblock; MessageBox(NULL, "DECODING DONE", "Status", NULL); }
void decodeProgressiveModeSpectralSelection(TwoByte* st){ int h = workingImage.getHeight(); int w = workingImage.getWidth(); Byte* imgd = workingImage.getImageData(); unsigned int q = 1<<quantizationLevel; TwoByte* tblock = new TwoByte[192]; Byte* idctblock = new Byte[192]; memset(tblock, 0x00, sizeof(TwoByte)*192); memset(idctblock, 0x00, sizeof(Byte)*192); for(int y = 0; y < h; y+=8){ for(int x = 0; x < w; x+=8){ for(int yy= 0; yy < 8; yy++){ for(int xx = 0; xx < 8; xx++){ int src = ((y + yy)*w + (x + xx))*3; int dest = (yy*8 + xx)*3; tblock[dest] = st[src]*q; tblock[dest + 1] = st[src + 1]*q; tblock[dest + 2] = st[src + 2]*q; } } doIDCT(tblock, idctblock); for(int yy= 0; yy < 8; yy++){ for(int xx = 0; xx < 8; xx++){ int dest = ((y + yy)*w + (x + xx))*3; int src = (yy*8 + xx)*3; imgd[dest] = idctblock[src]; imgd[dest + 1] = idctblock[src + 1]; imgd[dest + 2] = idctblock[src + 2]; } } } } delete[] tblock; delete[] idctblock; drawImage(&workingImage, nextStart); }
void encode(TwoByte *store){ int h = originalImage.getHeight(); int w = originalImage.getWidth(); Byte* imgd = originalImage.getImageData(); Byte* tblock = new Byte[192]; double* dctblock = new double[192]; memset(tblock, 0x00, sizeof(Byte)*192); memset(dctblock, 0x00, sizeof(double)*192); unsigned int q = 1<<quantizationLevel; for(int y = 0; y < h; y+=8){ for(int x = 0; x < w; x+=8){ for(int yy= 0; yy < 8; yy++){ for(int xx = 0; xx < 8; xx++){ int src = ((y+yy)*w + (x + xx))*3; int dest = (yy*8 + xx)*3; tblock[dest] = imgd[src]; tblock[dest + 1] = imgd[src + 1]; tblock[dest + 2] = imgd[src + 2]; } } doDCT(tblock, dctblock); for(int yy= 0; yy < 8; yy++){ for(int xx = 0; xx < 8; xx++){ int dest = ((y+yy)*w + (x + xx))*3; int src = (yy*8 + xx)*3; store[dest] = (TwoByte)(dctblock[src]/q); store[dest + 1] = (TwoByte)(dctblock[src + 1]/q); store[dest + 2] = (TwoByte)(dctblock[src + 2]/q); } } } } delete[] tblock; delete[] dctblock; }
void sendSuccessiveBits(void* storage){ TwoByte* st = (TwoByte*) storage; int h = workingImage.getHeight(); int w = workingImage.getWidth(); int len = h*w*3; TwoByte *newst = new TwoByte[len]; memset(newst, 0x00, sizeof(TwoByte)*len); TwoByte offset = 1<<12; for(int k = 12; k >= 0; --k){ for(int i = 0; i < len; ++i){ TwoByte temp = st[i] + offset; temp &= (1<<k); newst[i] |= temp; } decodeProgressiveModeBitApproximation(newst, offset); Sleep(latency); } delete[] newst; MessageBox(NULL, "DECODING DONE", "Status", NULL); }
// // FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; TCHAR szHello[MAX_LOADSTRING]; LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: { hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... RECT rt; GetClientRect(hWnd, &rt); // Top Text char text[1000]; // Image Header setup BITMAPINFO bmi; CBitmap bitmap; memset(&bmi,0,sizeof(bmi)); bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader); bmi.bmiHeader.biWidth = myImage.getWidth(); bmi.bmiHeader.biHeight = -myImage.getHeight(); // Use negative height. DIB is top-down. bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 24; bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biSizeImage = myImage.getWidth()*myImage.getHeight(); // Draw Processed image sprintf(text, "\n %s -> display", myImage.getImagePath()); DrawText(hdc, text, strlen(text), &rt, DT_LEFT); sprintf(text, "\n %s -> Gray Scaled -> YUV -> DCT -> Quant [ %d ] -> Dequant [ %d ] -> IDCT [ %d Co-Efficient(s) ] ", myImage.getImagePath(), myImage.getQuant(), myImage.getQuant(), myImage.getCoEff()); DrawText(hdc, text, strlen(text), &rt, DT_RIGHT); // Draw image SetDIBitsToDevice(hdc, 100,100,myImage.getWidth(),myImage.getHeight(), 0,0,0,myImage.getHeight(), myImage.getBytesRGBSTART(),&bmi,DIB_RGB_COLORS); SetDIBitsToDevice(hdc, 300+myImage.getWidth()+50,100,myImage.getWidth(),myImage.getHeight(), 0,0,0,myImage.getHeight(), myImage.getBytesRGBEND(),&bmi,DIB_RGB_COLORS); EndPaint(hWnd, &ps); } break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
void sendSpectralSelection(void* storage){ TwoByte* st = (TwoByte*) storage; int h = workingImage.getHeight(); int w = workingImage.getWidth(); int len = h*w*3; TwoByte *newst = new TwoByte[len]; memset(newst, 0x00, sizeof(TwoByte)*len); int xx, yy; int t = 0; for(int k= 0; k <= 14; ++k){ if((k%7)%2 == 0){ if(k == 7 || k==14){ xx = 7; yy = k-7; } else{ yy = k%7; xx = k-yy; } } else{ xx = k%7; yy = k-xx; } if(yy > xx){ t = yy - xx; for(int i = 0; i <= t; ++i){ for(int y = 0; y < h; y+=8){ for(int x = 0; x < w; x+=8){ int index = ((y + yy)*w + (x + xx))*3; newst[index] = st[index]; newst[index + 1] = st[index + 1]; newst[index + 2] = st[index + 2]; } } decodeProgressiveModeSpectralSelection(newst); Sleep(latency); yy--;xx++; } } else{ t = xx - yy; for(int i = 0; i <= t; ++i){ for(int y = 0; y < h; y+=8){ for(int x = 0; x < w; x+=8){ int index = ((y + yy)*w + (x + xx))*3; newst[index] = st[index]; newst[index + 1] = st[index + 1]; newst[index + 2] = st[index + 2]; } } decodeProgressiveModeSpectralSelection(newst); Sleep(latency); yy++;xx--; } } } delete[] newst; MessageBox(NULL, "DECODING DONE", "Status", NULL); }
bool compareImage_v2(MyImage &img_logo, MyImage &img_pic) { int row_n = img_pic.getHeight() / BLOCK_SIZE; int col_n = img_pic.getWidth() / BLOCK_SIZE; int *his_logo = getHistogram(img_logo, 0, 0, img_logo.getHeight(), img_logo.getWidth()); //int *his_logo = getHistogram_H(img_logo, 0, 0, img_logo.getHeight(), img_logo.getWidth()); //int *his_pic = getHistogram_H(img_pic, 0, 0, img_pic.getHeight(), img_pic.getWidth()); //print_arr(his_logo, histo_size); //print_arr(his_logo, histo_size_h); //delete his_pic; double *norm_logo = normalize(his_logo, histo_size); //double *norm_logo = normalize(his_logo, histo_size_h); //print_arr_d(norm_logo, histo_size); //print_arr_d(norm_logo, histo_size_h); int **block_histos = new int*[row_n * col_n]; int total_blc = 0; for(int i = 0; i < img_pic.getHeight(); i += BLOCK_SIZE) { for(int j = 0; j < img_pic.getWidth(); j += BLOCK_SIZE) { //TRACE("i: %d, j: %d\n", i, j); block_histos[total_blc++] = getHistogram(img_pic, i, j, i + BLOCK_SIZE, j + BLOCK_SIZE); // print_arr(block_histos[total_blc - 1], H_N); } } int window_size = min(row_n, col_n); //double min_diff = 1000.0; //int min_x = -1, min_y = -1, min_size = -1; std::priority_queue<Box, std::vector<Box>, CompareBox> best_boxes; int max_heap_size = 5; while(window_size > 0) { for(int row = 0; row <= row_n - window_size; row++) { for(int col = 0; col <= col_n - window_size; col++) { int *local_histo = new int[histo_size]; //int *local_histo = new int[histo_size_h]; for(int x = 0; x < histo_size; x++) local_histo[x] = 0; //for(int x = 0; x < histo_size_h; x++) local_histo[x] = 0; for(int x = row; x < row + window_size; x++) { for(int y = col; y < col + window_size; y++) { int block_index = x * col_n + y; for(int z = 0; z < histo_size; z++) //for(int z = 0; z < histo_size_h; z++) local_histo[z] += block_histos[block_index][z]; } } double *norm_local = normalize(local_histo, histo_size); //double *norm_local = normalize(local_histo, histo_size_h); //print_arr_d(norm_local, H_N); //print_arr_d(norm_logo, H_N); double diff = differ(norm_local, norm_logo, histo_size); //double diff = differ(norm_local, norm_logo, histo_size_h); //TRACE("row: %d, col: %d, size: %d, diff: %lf\n", row, col, window_size, diff); /* if(row == 3 && col == 6 && window_size == 2) { print_arr_d(norm_local, histo_size); TRACE("diff: %lf\n", diff); } */ if(best_boxes.size() == max_heap_size && best_boxes.top().diff > diff) { delete best_boxes.top().histogram; best_boxes.pop(); } if(best_boxes.size() < max_heap_size) { Box new_box = {row, col, window_size, diff, local_histo}; //TRACE("r: %d, c: %d, size: %d, diff: %lf\n", new_box.row, new_box.col, new_box.len, new_box.diff); best_boxes.push(new_box); } else delete local_histo; delete norm_local; } } window_size--; } //TRACE("row: %d, col: %d, size: %d, diff: %lf\n", min_y, min_x, min_size, min_diff); //int length = min_size * BLOCK_SIZE; img_pic.RGBtoGray(); img_logo.RGBtoGray(); unsigned char **pyramid = create_img_pyr(img_logo, 0); int min_err = (1 << 31) - 1; double min_diff = 10.0; //printf("here\n"); while(!best_boxes.empty()) { Box best_box = best_boxes.top(); TRACE("row: %d, col: %d, size: %d, diff: %lf\n", best_box.row, best_box.col, best_box.len, best_box.diff); //printf("row: %d, col: %d, size: %d, diff: %lf\n", best_box.row, best_box.col, best_box.len, best_box.diff); //print_arr(best_box.histogram, histo_size); //print_arr(best_box.histogram, histo_size_h); img_pic.DrawBox(best_box.row * BLOCK_SIZE, best_box.col * BLOCK_SIZE, (best_box.row + best_box.len)* BLOCK_SIZE, (best_box.col + best_box.len) * BLOCK_SIZE); best_boxes.pop(); if(best_boxes.empty()) min_err = diff_pic(pyramid[best_box.len - 1], best_box.len, img_pic, best_box.row * BLOCK_SIZE, best_box.col * BLOCK_SIZE, (best_box.row + best_box.len)* BLOCK_SIZE, (best_box.col + best_box.len) * BLOCK_SIZE); //TRACE("cur_err: %d\n", cur_err); //printf("cur_err: %d\n", cur_err); //if(cur_err < min_err) min_err = cur_err; if(best_box.diff < min_diff) min_diff = best_box.diff; delete best_box.histogram; } TRACE("min_square_error: %d\n", min_err); TRACE("min_diff: %f\n", min_diff); delete his_logo; delete norm_logo; //delete [] block_histos; for(int i = 0; i < total_blc; i++) { delete block_histos[i]; } for(int i = 0; i < 9; i++) { delete pyramid[i]; } delete pyramid; delete block_histos; if(min_diff <= 0.02) return true; if(min_diff >= 0.33) return false; return min_err < 400000; }