⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wavzwin.cpp

📁 wavlet compression on c++ only cods
💻 CPP
📖 第 1 页 / 共 2 页
字号:
       if (selected_max_bit_plane < bit_plane_total)
	  bit_plane_total = selected_max_bit_plane;

    message_printf (MB_INFO,"Zerotree Encoding",
      "Max value: %6.2f\r\n"
      "Threshold: %6.2f\r\n"
      "Max Bit Plane: %d\r\n"
      "Selected Max Bit Plane: %d",
      max,threshold,log_2_threshold+1,
      bit_plane_total);

    fwrite (&(wavelet_type),sizeof(wavelet_type),1,output);
    // Assume square image (rows = cols), so we only output rows:
    fwrite (&(rows),sizeof(rows),1,output);
    // Keep wavelet_array->lowpass_value separate from thresholding
    fwrite (&(wavelet_array->lowpass_value),sizeof(wavelet_array->lowpass_value),
      1,output);
    fwrite (&(log_2_threshold),sizeof(log_2_threshold),1,output);
    fwrite (&(bit_plane_total),sizeof(bit_plane_total),1,output);

    while (threshold >= 1) {
    start_time = time(NULL);
    symbol_array->init(0);

    bit_plane_count++;

    // Check LH band from the bottom up:
    z_end_row = rows/2;
    z_start_row = 1;
    z_end_col = cols;
    z_start_col = z_end_col/2 + 1;

    while (z_end_col>=2) {
	for (i=z_start_row;i<=z_end_row;i++)
	    for (j=z_start_col;j<=z_end_col;j++) {
		if (fabs(wavelet_array->values[i][j]) > threshold) {
		   if (wavelet_array->values[i][j] > 0)
		      symbol_array->set(i,j,POS);
		   else symbol_array->set(i,j,NEG);
		   // Mark the parents as having a significant child.
		   // Note: The 'IZ' symbol may be overwritten later with
		   // 'POS' or 'NEG' if that coefficient is itself found
		   // to be significant.
		   symbol_array->mark_parents (i,j,IZ);
		   }  // end if
		} // end i,j
	 z_end_row /= 2;
	 z_end_col /= 2;
	 z_start_row = 1;
	 z_start_col = z_end_col/2 + 1;
	 }  // end while

    // Now all significant coefficients have been coded as POS or NEG,
    // and all isolated coefficients have been coded as IZ.
    // We now need to determine the zerotree roots.
    // Check LH band from the top down:
    z_end_row = 1;
    z_start_row = 1;
    z_end_col = 2;
    z_start_col = 2;

    while ((z_end_row<=rows)&&(z_end_col<=cols)) {
	for (i=z_start_row;i<=z_end_row;i++)
	    for (j=z_start_col;j<=z_end_col;j++) {
		symbol = symbol_array->get(i,j);
		switch (symbol) {
		case POS:
		case NEG:
		case IZ:
		   write_symbol(symbol,output);
		   break;
		case ZT:
		   break;  // Don't write ZT symbols
		case 0:
		   if ((z_end_row<=rows/2)&&(z_end_col<=cols/2)) {
		      symbol_array->set(i,j,ZR);
		      write_symbol(symbol_array->array[i][j],output);
		      // Mark children as zerotree children:
		      symbol_array->mark_children (i,j,rows,cols,ZT);
		      }
		   else {
		      symbol_array->set(i,j,IZ);
		      write_symbol(symbol_array->array[i][j],output);
		      }
		   break;
		   }  // end switch
                }  // end i,j
	z_end_row *= 2;
	z_start_row = 1;
	z_start_col = z_end_col+1;
	z_end_col *= 2;
	}  // end while

    // Check HH band from the bottom up:
    z_end_row = rows;
    z_start_row = z_end_row/2 + 1;
    z_end_col = cols;
    z_start_col = z_end_col/2 + 1;

    while (z_end_col>=2) {
	for (i=z_start_row;i<=z_end_row;i++)
	    for (j=z_start_col;j<=z_end_col;j++) {
		if (fabs(wavelet_array->values[i][j]) > threshold) {
		   if (wavelet_array->values[i][j] > 0)
		      symbol_array->set(i,j,POS);
		   else symbol_array->set(i,j,NEG);
		   // Mark the parents as having a significant child.
		   // Note: The 'IZ' symbol may be overwritten later with
		   // 'POS' or 'NEG' if that coefficient is itself found
		   // to be significant.
		   symbol_array->mark_parents (i,j,IZ);
		   }  // end if
		} // end i,j
	 z_end_row /= 2;
	 z_end_col /= 2;
	 z_start_row = z_end_row/2 + 1;
	 z_start_col = z_end_col/2 + 1;
	 }  // end while
    // Now all significant coefficients have been coded as POS or NEG,
    // and all isolated coefficients have been coded as IZ.
    // We now need to determine the zerotree roots.
    // Check HH band from the top down:
    z_end_row = 2;
    z_start_row = 2;
    z_end_col = 2;
    z_start_col = 2;

    while ((z_end_row<=rows)&&(z_end_col<=cols)) {
	for (i=z_start_row;i<=z_end_row;i++)
	    for (j=z_start_col;j<=z_end_col;j++) {
		symbol = symbol_array->get(i,j);
		switch (symbol) {
		case POS:
		case NEG:
		case IZ:
		   write_symbol(symbol,output);
		   break;
		case ZT:
		   break;  // Don't write ZT symbols
		case 0:
		   if ((z_end_row<=rows/2)&&(z_end_col<=cols/2)) {
		      symbol_array->set(i,j,ZR);
		      write_symbol(symbol_array->array[i][j],output);
		      // Mark children as zerotree children:
		      symbol_array->mark_children (i,j,rows,cols,ZT);
		      }
		   else {
		      symbol_array->set(i,j,IZ);
		      write_symbol(symbol_array->array[i][j],output);
		      }
		   break;
		   }  // end switch
		}  // end i,j
	z_start_row = z_end_row + 1;
	z_end_row *= 2;
	z_start_col = z_end_col + 1;
	z_end_col *= 2;
	}  // end while

    // Check HL band from the bottom up:
    z_end_row = rows;
    z_start_row = z_end_row/2 + 1;
    z_end_col = cols/2;
    z_start_col = 1;

    while (z_end_row>=2) {
	for (i=z_start_row;i<=z_end_row;i++)
	    for (j=z_start_col;j<=z_end_col;j++) {
		if (fabs(wavelet_array->values[i][j]) > threshold) {
		   if (wavelet_array->values[i][j] > 0)
		      symbol_array->set(i,j,POS);
		   else symbol_array->set(i,j,NEG);
		   // Mark the parents as having a significant child.
		   // Note: The 'IZ' symbol may be overwritten later with
		   // 'POS' or 'NEG' if that coefficient is itself found
		   // to be significant.
		   symbol_array->mark_parents (i,j,IZ);
		   }  // end if
		} // end i,j
	 z_end_row /= 2;
	 z_end_col /= 2;
	 z_start_row = z_end_row/2 + 1;
	 z_start_col = 1;
	 }  // end while
    // Now all significant coefficients have been coded as POS or NEG,
    // and all isolated coefficients have been coded as IZ.
    // We now need to determine the zerotree roots.
    // Check HL band from the top down:
    z_end_row = 2;
    z_start_row = 2;
    z_end_col = 1;
    z_start_col = 1;

    while ((z_end_row<=rows)&&(z_end_col<=cols)) {
	for (i=z_start_row;i<=z_end_row;i++)
	    for (j=z_start_col;j<=z_end_col;j++) {
		symbol = symbol_array->get(i,j);
		switch (symbol) {
		case POS:
		case NEG:
		case IZ:
		   write_symbol(symbol,output);
		   break;
		case ZT:
		   break;  // Don't write ZT symbols
		case 0:
		   if ((z_end_row<=rows/2)&&(z_end_col<=cols/2)) {
		      symbol_array->set(i,j,ZR);
		      write_symbol(symbol_array->array[i][j],output);
		      // Mark children as zerotree children:
		      symbol_array->mark_children (i,j,rows,cols,ZT);
		      }
		   else {
		      symbol_array->set(i,j,IZ);
		      write_symbol(symbol_array->array[i][j],output);
		      }
		   break;
		   }  // end switch
		} // end i,j
	z_start_row = z_end_row + 1;
	z_end_row *= 2;
	z_start_col = 1;
	z_end_col *= 2;
	}  // end while

    // Now subtract threshold from significant wavelet values:
    for (i=1;i<=rows;i++)
	for (j=1;j<=cols;j++) {
	    if (symbol_array->get(i,j) == POS)
	       wavelet_array->values[i][j] -= threshold;
	    if (symbol_array->get(i,j) == NEG)
	       wavelet_array->values[i][j] += threshold;
	    int_value = (symbol_array->get(i,j)-1)*z_incr;
	    if (int_value <= 0) int_value = 0;
	    if (int_value >= WAV_GRAY_LEVELS-1) int_value = WAV_GRAY_LEVELS-1;
	    wavelet_image->s.pixel[i][j] = int_value;
	    }  // end i,j

    end_time = time(NULL);

    compression_time += end_time - start_time;

    if ((show_bit_planes)||(bit_plane_count >= bit_plane_total)) {
       display_image = wavelet_image;
       show_gray_image(wavelet_image);
       }

    threshold /= 2;

    if (bit_plane_count >= bit_plane_total) break;

    }  // end while

    // Write out last byte if necessary:
    if (bit_count)
       for (i=bit_count;i<=NO_OF_BIT_SYMBOLS-1;i++)
	   write_symbol(IZ,output);

    fclose (output);

    SetCursor (save_cursor);
    delete wavelet_array;
    free_matrix2d (values,1,rows,1);

    sprintf ((char *)the_title,"%s (%5.2f%%): %s",wavelet_name,
	  compression_percent,(char *)image_filename);
    SetWindowText (hwindow,the_title);

    message_printf (MB_INFO,"Zerotree Encoding Time",
      "Transform Time:      %ld\r\n"
      "Decimation Time:     %ld\r\n"
      "Total Encoding Time: %ld\r\n",
      wavelet_transform_time,decimation_time,compression_time);

    return 1;
    }

int twavelet_zerotree_window::respond_wm_paint () {
    PAINTSTRUCT  ps;
    if (!hbitmap) {
       HDC hdc = BeginPaint (hwindow,&ps);
       show_bitmap_image(hdc,himage_bitmap,p_image_palette);
       EndPaint (hwindow, &ps);
       return 1;
       }
    return twavelet_window::respond_wm_paint();
   }

int twavelet_zerotree_window::respond_wm_mdiactivate (HWND hwnd,
		 WPARAM wParam,LPARAM lParam) {
    if ACTIVATE_MDI_CHILD_WINDOW(hwnd,wParam,lParam)
          SendMessage (manager->hwndClient, WM_MDISETMENU,
	  MDI_SETMENU_MSGPARAMS(manager->window_menu,
	  manager->window_submenu)) ;

    // check or uncheck menu items

    CheckMenuItem (manager->window_menu, WAV_SHOW_BIT_PLANES,
	 show_bit_planes ? MF_CHECKED : MF_UNCHECKED) ;

    // Set the Init menu if losing focus
    if (!ACTIVATE_MDI_CHILD_WINDOW(hwnd,wParam,lParam))
	  SendMessage (manager->hwndClient, WM_MDISETMENU,
	  MDI_SETMENU_MSGPARAMS(manager->frame_menu,
	  manager->frame_submenu)) ;

    DrawMenuBar (manager->hwndFrame) ;
    return 1 ;
    }

int twavelet_zerotree_window::respond_wm_command (WPARAM wParam,LPARAM) {
    switch (wParam)
       {
       case WAV_GRAY_IMAGE:
	    if (!symbol_array) show_symbols = 0;
	    OnRun();
	    show_symbols = 1;
            return 1;
       case WAV_ZEROTREE_MAX_BIT_PLANE:
	    return get_max_bit_plane();
       case WAV_TRANSFORM:
	    show_symbols = 0;
	    show_wavelet_transform();
	    show_symbols = 1;
	    return 1;
       case WAV_SHOW_BIT_PLANES:
	    show_bit_planes = !show_bit_planes;
	    CheckMenuItem (manager->window_menu, WAV_SHOW_BIT_PLANES,
		   show_bit_planes ? MF_CHECKED : MF_UNCHECKED);
	    break;
       }  // end switch
    return twavelet_window::respond_wm_command (wParam,0L);
    }

int twavelet_zerotree_window::respond_wm_destroy (HWND hwnd) {
    if (symbol_array) delete symbol_array;
    twavelet_window::respond_wm_destroy (hwnd);
    return 1;
    }









⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -