📄 cips4.c
字号:
my_moveto(x+100, y);
my_lineto(x+100, y-95);
my_moveto(x+150, y);
my_lineto(x+150, y-95);
my_moveto(x+200, y);
my_lineto(x+200, y-95);
my_moveto(x+255, y);
my_lineto(x+255, y-95);
/***************************
*
* loop thru the histogram
* and plot the scaled data
*
****************************/
my_setlinestyle(0xFFFF);
my_setcolor(data_color);
for(i=0; i<256; i++){
if(histogram[i] != 0){
length = histogram[i]/scale;
my_moveto(x+i, y);
my_lineto(x+i, y-length);
}
} /* ends loop over i GRAY_LEVELS */
} /* ends display_histogram */
/*****************************************
*
* display_menu_for_histogram(...
*
* This function shows the options
* available for histogram function.
*
****************************************/
display_menu_for_histogram(print, vertical,
horizontal)
int *print, *vertical, *horizontal;
{
char response[80];
int int_response, not_finished, r;
not_finished = 1;
while(not_finished){
printf(
"\n\nHISTOGRAM> Enter choice (0 for no change)");
printf(
"\nHISTOGRAM> 1. print is %d (1=print 0=display)",
*print);
printf(
"\nHISTOGRAM> 2. # of vertical %dx%d areas %d",
ROWS, COLS, *vertical);
printf(
"\nHISTOGRAM> 3. # of horizontal %dx%d areas %d",
ROWS,COLS,*horizontal);
printf("\nHISTOGRAM> _\b");
get_integer(&r);
if(r == 0)
not_finished = 0;
if(r == 1){
printf(
"\nHISTOGRAM> Enter 1 for print or 0 for display");
printf("\nHISTOGRAM> ___");
get_integer(&int_response);
*print = int_response;
} /* ends if r == 1 */
if(r == 2){
printf(
"\nHISTOGRAM> Enter # of vertical %dx%d areas ",
ROWS,COLS);
printf("\nHISTOGRAM> _\b");
get_integer(&int_response);
*vertical = int_response;
} /* ends if r == 2 */
if(r == 3){
printf(
"\nHISTOGRAM> Enter # of horizontal %dx%d areas ",
ROWS,COLS);
printf("\nHISTOGRAM> ___");
get_integer(&int_response);
*horizontal = int_response;
} /* ends if r == 3 */
} /* ends while not_finished */
} /* ends display_menu */
/********************************************
*
* calculate_area_histogram(...
*
* This function calculates the histogram
* for several ROWSxCOLS arrays of an
* image. The user inputs the number
* of vertical and horizontal ROWSxCOLS
* arrays to be histogramed. This function
* uses the image file name to read the image
* arrays and calculate the overall
* histogram.
*
*********************************************/
calculate_area_histogram(histogram, vertical,
horizontal, the_image, name, il,
ie, ll, le)
char name[];
int horizontal, il, ie, ll, le, vertical;
short the_image[ROWS][COLS];
unsigned long histogram[];
{
int count, i, j;
printf("\nCalculating histograms");
zero_histogram(histogram);
count = 1;
for(i=0; i<vertical; i++){
for(j=0; j<horizontal; j++){
printf("\n\tcalculating %d of %d",
count, horizontal*vertical);
read_tiff_image(name, the_image,
il+i*ROWS, ie+j*COLS,
ll+i*ROWS, le+j*COLS);
calculate_histogram(the_image, histogram);
count++;
} /* ends loop over j */
} /* ends loop over i */
} /* calcualte_area_histogram */
/********************************************
*
* smooth_histogram(...
*
* This function smoothes the input histogram
* and returns it. It uses a simple averaging
* scheme where each point in the histogram
* is replaced by the average of itself and
* the two points on either side of it.
*
*********************************************/
smooth_histogram(histogram)
unsigned long histogram[];
{
int i;
unsigned long new_hist[GRAY_LEVELS+1];
zero_histogram(new_hist);
new_hist[0] = (histogram[0] + histogram[1])/2;
new_hist[GRAY_LEVELS] =
(histogram[GRAY_LEVELS] +
histogram[GRAY_LEVELS-1])/2;
for(i=1; i<GRAY_LEVELS; i++){
new_hist[i] = (histogram[i-1] +
histogram[i] +
histogram[i+1])/3;
}
for(i=0; i<=GRAY_LEVELS; i++)
histogram[i] = new_hist[i];
} /* ends smooth_histogram */
hist_long_clear_buffer(string)
char string[];
{
int i;
for(i=0; i<300; i++)
string[i] = ' ';
}
/**************************************************
*
* file d:\cips\pi.c
*
* Functions: This file contains
* print_image
* print_image_array
* perform_printing
* print_column_header
*
* Purpose - These functions print an image out
* to the line printer. The parameters in
* this function are defined differently
* than in most other CIPS functions.
* The parameters il, ie, ll, le are
* coordinates inside the 100x100 image array.
* The parameters first_line and first_element
* are coordinates for the entire image file.
* So, if you want to start printing at row 10
* and column 10 of the image file you would
* call:
*
* read_tiff_image(name, the_image, 10, 10,
* 110, 110);
* print_image(the_image, name, 1, 1, 1,
* 100, 18, 10, 10);
*
* In normal print mode you can only print 17
* columns.
* le - ie = 17.
*
*
* External Calls:
* none
*
* Modifications:
* 6 January 1987 - created
* 14 August 1990 - modified to be part of the
* C Image Processing System
* 14 June 1993 - removed calls to
* my_fwrite my_fwriteln
*
**************************************************/
#define FORMFEED '\014'
/*********************************************
*
* printf_image(...
*
*********************************************/
print_image(the_image, name, channel, il, ie, ll, le,
first_line, first_element)
char name[];
int channel, il, ie, ll, le,
first_line, first_element;
short the_image[ROWS][COLS];
{
char printer_name[MAX_NAME_LENGTH];
FILE *printer;
strcpy(printer_name, "prn");
if( (printer = fopen(printer_name, "w")) == NULL)
printf("\nPI> Could not open printer");
else{
printf("\nPI> The print file is opened");
/*****************************************
*
* If your printer has some form of
* condensed printing, you can send those
* commands via software using the fputc
* function. For example, if your printer
* needs to sequence X Y Z to start
* condensed printing, insert the following
* three calls right here:
* fputc('X', printer);
* fputc('Y', printer);
* fputc('Z', printer);
*
******************************************/
perform_printing(printer, the_image, name,
channel, il, ll, ie, le,
first_line, first_element);
fclose(printer);
} /* ends else print */
} /* ends print_image */
/*********************************************
*
* perform_printing(...
*
*********************************************/
perform_printing(printer, the_image, name, channel,
il, ll, ie, le, first_line,
first_element)
char name[];
FILE *printer;
int channel, il, ie, ll, le,
first_line, first_element;
short the_image[ROWS][COLS];
{
char output[3*COLS],
response[80],
string[3*COLS];
int i,
j,
k,
line_counter;
printf("\nPI> Print header");
line_counter = 0;
pi_long_clear_buffer(string);
sprintf(string, " This image is -- %s --\n",
name);
fputs(string, printer);
++line_counter;
pi_long_clear_buffer(string);
sprintf(string, " The parameters are:\n");
fputs(string, printer);
++line_counter;
pi_long_clear_buffer(string);
sprintf(string,
" channel=%d il=%d ll=%d ie=%d le=%d\n",
channel, first_line, first_line+ll-2,
first_element, first_element+le-2);
fputs(string, printer);
++line_counter;
pi_long_clear_buffer(string);
sprintf(string, " \n");
fputs(string, printer);
++line_counter;
print_column_header(&line_counter, first_element,
ie, le, output, string,
printer);
for(i=il; i<ll; i++){
pi_long_clear_buffer(string);
/* now print the image */
sprintf(string, " ");
pi_long_clear_buffer(output);
sprintf(output, "%3d-", i+first_line-1);
strcat(string, output);
for(j=ie; j<le; j++){
pi_long_clear_buffer(output);
sprintf(output,"%4d",the_image[i][j]);
strcat(string, output);
} /* ends loop over j columns */
fputs(string, printer); fputc('\n', printer);
line_counter = line_counter + 1;
if(line_counter >= 53){
line_counter = 0;
putc(FORMFEED, printer);
print_column_header(&line_counter,
first_element, ie,
le, output, string,
printer);
} /* ends if line_counter >=65 */
} /* ends loop over i rows */
for(i=line_counter; i<66; i++){
pi_long_clear_buffer(string);
sprintf(string, " \n");
fputs(string, printer);
}
} /* ends perform_printing */
/*********************************************
*
* print_column_header(...
*
*********************************************/
print_column_header(line_counter, first_element,
ie, le, output,
string, printer)
char string[], output[];
FILE *printer;
int first_element, ie, le, *line_counter;
{
int k;
pi_long_clear_buffer(string);
sprintf(string, " ");
for(k=first_element;k<(first_element+(le-ie));k++){
pi_long_clear_buffer(output);
sprintf(output, "-%3d", k);
strcat(string, output);
} /* ends loop over k */
fputs(string, printer); fputc('\n', printer);
*line_counter = *line_counter + 1;
} /* ends print_column_header */
/*************************************************
*
* print_image_array(...
*
* This function prints a 100x100 image array.
*
**************************************************/
print_image_array(the_image)
short the_image[ROWS][COLS];
{
char response[80];
printf("\nPIA> Enter a comment line\n--");
gets(response);
/* il ie ll le */
print_image(the_image, response, 0, 1, 1, 100, 17, 0, 0);
print_image(the_image, response, 0, 1, 18, 100, 35, 0, 0);
print_image(the_image, response, 0, 1, 36, 100, 53, 0, 0);
print_image(the_image, response, 0, 1, 54, 100, 71, 0, 0);
print_image(the_image, response, 0, 1, 72, 100, 89, 0, 0);
print_image(the_image, response, 0, 1, 90, 100, 100, 0, 0);
} /* ends print_image_array */
/*********************************************
*
* pi_long_clear_string(...
*
*********************************************/
pi_long_clear_buffer(string)
char string[];
{
int i;
for(i=0; i<300; i++)
string[i] = ' ';
}
/**************************************************
*
* file d:\cips\ht.c
*
* Functions: This file contains
* display_using_halftoning
* half_tone
* show_half_tone
* get_threshold_value
*
* Purpose: This program displays an image using
* a halftoning process. The algorithm was
* taken from "Personal computer based image
* processing with halftoning," John A Saghri,
* Hsieh S. Hou, Andrew Tescher, Optical
* Engineering, March 1986, Vol.25, No. 3,
* pp 499-503. The display_using_halftoning
* determines display size and reads the image.
* The half_tone function implements the
* algorithm shown on page 502 of the article.
*
* The function print_halftone_array prints
* a half toned image array to a regular line
* printer.
*
*
* External Calls:
* rtiff.c - read_tiff_image
* numcvrt.c - get_integer
*
* Modifications:
* 30 September 86 - created
* 18 August 1990 - modified for use in the
* C Image Processing System.
*
*
**************************************************/
#define FORMFEED '\014'
float eg[ROWS][COLS], ep[ROWS][COLS];
display_using_halftoning(in_image, file_name,
il, ie, ll, le, threshold, invert,
image_colors, image_header, monitor_type,
print, show_hist, color_transform)
char color_transform[], file_name[],
monitor_type[];
int image_colors, invert,
il, ie, ll, le, threshold,
print, show_hist;
short in_image[ROWS][COLS];
struct tiff_header_struct *image_header;
{
char response[80];
int a,
b,
channel,
color,
count,
data_color,
display_mode,
horizontal,
i,
j,
k,
l,
line_color,
max_horizontal,
max_vertical,
not_finished,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -