📄 delas.c
字号:
* writing ELAS image headers. They pack and
* unpack floating point numbers and integers
* from a buffer of characters.
*
* External Calls:
* none
*
* Modifications:
* July 1986 - ported to IBM-PC
*
*********************************************************/
long_equate(buffer, lcu, start)
char buffer[];
int start;
union long_char_union *lcu;
{
int i;
lcu->l_num = 0;
for(i=0; i<4; i++){
lcu->l_alpha[3-i] = buffer[start + i];
} /* this is i not 3-i on none 8086 systems */
/* the same is true for the other functions */
/* in this file */
}
float_equate(buffer, fcu, start)
char buffer[];
int start;
union float_char_union *fcu;
{
int i;
for(i=0; i<4; i++)
fcu->f_alpha[3-i] = buffer[start + i];
}
store_long_into_buffer(buffer, lcu, start)
char buffer[];
int start;
union long_char_union *lcu;
{
int i;
for(i=0; i<4; i++)
buffer[start + i] = lcu->l_alpha[3-i];
}
store_float_into_buffer(buffer, fcu, start)
char buffer[];
int start;
union float_char_union *fcu;
{
int i;
for(i=0; i<4; i++)
buffer[start + i] = fcu->f_alpha[3-i];
}
/******************************************************
*
* file c:\lsu\intcvrt.c
*
* Functions: This file contains
* get_integer
* int_convert
*
* Purpose: These functions convert
a string of
* characters to their number value.
*
* Modifications:
* Taken from Jamsa's software package
* and altered to fit into the computer
* vision programming 22 August 1986.
*
*******************************************************/
#include "d:\tc\numdefs.h"
get_integer(n)
int *n;
{
char string[80];
read_string(string);
int_convert(string, n);
}
int_convert (ascii_val, result)
char *ascii_val;
int *result;
{
int sign = 1; /* -1 if negative */
*result = 0; /* value returned to the calling routine */
/* read passed blanks */
while (is_blank(*ascii_val))
ascii_val++; /* get next letter */
/* check for sign */
if (*ascii_val == '-' || *ascii_val == '+')
sign = (*ascii_val++ == '-') ? -1 : 1; /* find sign */
/*
* convert the ASCII representation to the actual
* decimal value by subtracting '0' from each character.
*
* for example, the ASCII '9' is equivalent to 57 in decimal.
* by subtracting '0' (or 48 in decimal) we get the desired
* value.
*
* if we have already converted '9' to 9 and the next character
* is '3', we must first multiply 9 by 10 and then convert '3'
* to decimal and add it to the previous total yielding 93.
*
*/
while (*ascii_val)
if (is_digit(*ascii_val))
*result = *result * 10 + to_decimal(*ascii_val++);
else
return (IO_ERROR);
*result = *result * sign;
return (NO_ERROR);
}
color_transform(pixel, key, type_of_transform)
char type_of_transform[];
int key;
short pixel;
{
unsigned int color;
if( (type_of_transform[0] == 'M') ||
(type_of_transform[0] == 'm')){
if(key == 1){
if((pixel >= 0) && (pixel < 16)) color = 0;
if((pixel >= 16) && (pixel < 32)) color = 1;
if((pixel >= 32) && (pixel < 48)) color = 2;
if((pixel >= 48) && (pixel < 64)) color = 3;
if((pixel >= 64) && (pixel < 80)) color = 4;
if((pixel >= 80) && (pixel < 96)) color = 5;
if((pixel >= 96) && (pixel < 190)) color = 8;
/*if((pixel >= 112) && (pixel < 128)) color = 7;
if((pixel >= 128) && (pixel < 144)) color = 8;
if((pixel >= 150) && (pixel < 160)) color = 9;
if((pixel >= 160) && (pixel < 176)) color = 10;
if((pixel >= 176) && (pixel < 192)) color = 11;
if((pixel >= 190) && (pixel < 208)) color = 12;
if((pixel >= 208) && (pixel < 224)) color = 13;
if((pixel >= 224) && (pixel < 240)) color = 14;*/
if((pixel >= 190) && (pixel <= 255)) color = 15;
} /* ends if key == 1 */
if(key == 2){
if((pixel >= 0) && (pixel < 16)) color = 0;
if((pixel >= 16) && (pixel < 32)) color = 1;
if((pixel >= 32) && (pixel < 48)) color = 2;
if((pixel >= 48) && (pixel < 64)) color = 3;
if((pixel >= 64) && (pixel < 80)) color = 4;
if((pixel >= 80) && (pixel < 96)) color = 5;
if((pixel >= 96) && (pixel < 190)) color = 6;
if((pixel >= 112) && (pixel < 128)) color = 7;
if((pixel >= 128) && (pixel < 144)) color = 8;
if((pixel >= 150) && (pixel < 160)) color = 9;
if((pixel >= 160) && (pixel < 176)) color = 10;
if((pixel >= 176) && (pixel < 192)) color = 11;
/*if((pixel >= 190) && (pixel < 208)) color = 12;
if((pixel >= 208) && (pixel < 224)) color = 13;
if((pixel >= 224) && (pixel < 240)) color = 14;*/
if((pixel >= 192) && (pixel <= 255)) color = 15;
} /* ends if key == 2 */
if(key == 3){
if((pixel >= 0) && (pixel < 16)) color = 0;
if((pixel >= 16) && (pixel < 30)) color = 1;
if((pixel >= 30) && (pixel < 55)) color = 2;
if((pixel >= 55) && (pixel < 64)) color = 3;
if((pixel >= 64) && (pixel < 80)) color = 4;
if((pixel >= 80) && (pixel < 96)) color = 5;
if((pixel >= 96) && (pixel < 190)) color = 6;
if((pixel >= 112) && (pixel < 120)) color = 7;
if((pixel >= 120) && (pixel < 140)) color = 8;
if((pixel >= 140) && (pixel < 160)) color = 9;
if((pixel >= 160) && (pixel < 176)) color = 10;
if((pixel >= 176) && (pixel < 192)) color = 11;
if((pixel >= 192) && (pixel < 208)) color = 12;
if((pixel >= 208) && (pixel < 224)) color = 13;
if((pixel >= 224) && (pixel < 240)) color = 14;
if((pixel >= 240) && (pixel < 255)) color = 15;
} /* ends if key == 3 */
} /* ends if type_of_transform == Modified */
if( (type_of_transform[0] == 'S') ||
(type_of_transform[0] == 's'))
color = pixel/16;
if( (type_of_transform[0] == 'R') ||
(type_of_transform[0] == 'r')){
if(pixel == 0) color = 3;
if(pixel == 40) color = 6;
if(pixel == 41) color = 9;
if(pixel == 69) color = 12;
if(pixel == 97) color = 15;
} /* ends results mode */
return(color);
} /* ends color_transform */
/*****************************************************
********
*
* file c:\lsu\mof.c
*
* Functions: This file contains
* my_open
*
* Purpose: This function opens a file. Borland's
* Turbo C opens files a little different from
* the standard UNIX C. Instead of using this
* different method in a number of various
files,
* the method is placed in this one file. If the
* programs are moved to another system, all
changes
* will be located in this one place.
*
* External Calls:
* none
*
* Modifications:
* 18 June 1987 - created
*
******************************************************
*********/
my_open(file_name)
char file_name[];
{
int file_descriptor;
file_descriptor = open(file_name, O_RDWR | O_CREAT | O_BINARY,
S_IWRITE);
return(file_descriptor);
} /* ends my_open */
/**********************************************
*
* map_16_shades_of_gray(...
*
* This function maps 16 shades of gray into
* the first 16 color indices. This allows
* you to display a true "black and white"
* image on a color monitor.
*
*********************************************/
map_16_shades_of_gray(display_mode)
int display_mode;
{
/* all MSC 6.0 statements */
_setvideomode(display_mode);
_remappalette(0, 0x000000L);
_remappalette(1, 0x040404L);
_remappalette(2, 0x080808L);
_remappalette(3, 0x0c0c0cL);
_remappalette(4, 0x101010L);
_remappalette(5, 0x141414L);
_remappalette(6, 0x181818L);
_remappalette(7, 0x1c1c1cL);
_remappalette(8, 0x202020L);
_remappalette(9, 0x242424L);
_remappalette(10, 0x282828L);
_remappalette(11, 0x2c2c2cL);
_remappalette(12, 0x303030L);
_remappalette(13, 0x343434L);
_remappalette(14, 0x383838L);
_remappalette(15, 0x3f3f3fL);
}
/**********************************
*
* Modes for the SigmaVGA Legend
* (hex)
* 10 - 640x350x64?
* 12 - 640x480x16
* 29 - 800x600x16
* 30 - 800x600x256
* 38 - 1024x768x256
*
***********************************/
my_set_video_mode()
{
union REGS regs;
regs.h.al = 0x29; /* mode */
regs.h.ah = 0x00;
int86(0x10, ®s, ®s);
} /* ends my_set_video_mode */
my_set_pixel(x, y, color)
unsigned int x, y, color;
{
union REGS regs;
regs.h.ah = 0x0c;
regs.x.dx = y;
regs.x.cx = x;
regs.h.al = color;
regs.h.bh = 0;
int86(0x10, ®s, ®s);
} /* ends my_set_pixel */
lookup(color)
int color;
{
int table[16] =
{0, 1, 4, 5, 8, 2, 6, 9, 3, 12, 13, 7, 10, 11, 14, 15};
return(table[color]);
} /* ends lookup */
my_set_colors()
{
_asm{
mov ax,0029h ; 800x600x16
int 10h
mov ah,10h
mov al,1bh
mov bx,0h
mov cx,100h
int 10h
}
} /* ends my_set_colors */
/*****************************************
*
* perform_histogram_equalization(...
*
******************************************/
perform_histogram_equalization(image, histogram, new_grays, area)
float new_grays, area;
short image[ROWS][COLS];
unsigned long histogram[];
{
int i,
j,
k;
unsigned long sum,
sum_of_h[256];
double constant;
sum = 0;
for(i=0; i<256; i++){
sum = sum + histogram[i];
sum_of_h[i] = sum;
}
/* constant = new # of gray levels div by area */
/*constant = new_grays/area;*/
constant = 0.0004; /* 16/40000 = 0.0004 */
for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
k = image[i][j];
image[i][j] = sum_of_h[k] * constant;
}
}
} /* ends perform_histogram_equalization */
/*****************************************
*
* zero_long_histogram(...
*
******************************************/
zero_long_histogram(histogram)
unsigned long histogram[];
{
int i;
for(i=0; i<256; i++)
histogram[i] = 0;
} /* ends zero_long_histogram */
/*****************************************
*
* calcualte_long_histogram(...
*
******************************************/
calculate_long_histogram(image, histogram)
short image[ROWS][COLS];
unsigned long histogram[];
{
int i,j,k;
for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
k = image[i][j];
histogram[k] = histogram[k] + 1;
}
}
} /* ends calculate_long_histogram */
blank_out_display()
{
int i;
_setlinestyle(0xFFFF);
_setcolor(10);
for(i=0; i<640;i++){
_moveto(i, 0);
_lineto(i, 480);
}
} /* ends blank_out_display */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -