Bibliothèque de traitements d'images en virgule flottante. http://la.buvette.org/photos/cumul/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

182 lines
4.0 KiB

/*
* programme de test pour
* les fonctions de base.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
#include "../floatimg.h"
int verbosity;
/* ---------------------------------------------------------------- */
int essai_normalize(void)
{
FloatImg A;
float val;
int foo;
foo = fimg_create(&A, 512, 512, FIMG_TYPE_RGB);
if (foo) {
fprintf(stderr, "%s err create A %d\n", __func__, foo);
return foo;
}
fimg_drand48(&A, 255.0);
val = fimg_get_maxvalue(&A);
fprintf(stderr, "BEFORE max pixel %f\n", val);
A.fval = 255.0; A.count = 1;
foo = fimg_normalize(&A, 1.0, 0);
if (foo) {
fprintf(stderr, "%s err normalize A %d\n", __func__, foo);
return foo;
}
val = fimg_get_maxvalue(&A);
fprintf(stderr, "AFTER max pixel %f\n", val);
return 0;
}
/* ---------------------------------------------------------------- */
int essai_2gray(FloatImg *picz, char *outname)
{
int foo;
FloatImg gray;
fprintf(stderr, ">>> %s ( %p '%s' )\n", __func__, picz, outname);
foo = fimg_create(&gray, picz->width, picz->height, FIMG_TYPE_GRAY);
if (foo) {
fprintf(stderr, "%s : err %d on fimg create\n", __func__, foo);
exit(1);
}
foo = fimg_mk_gray_from(picz, &gray, 0);
if (foo) {
fprintf(stderr, "%s : err %d on fimg mk_gray_from\n", __func__, foo);
exit(1);
}
foo = fimg_save_as_pnm(&gray, outname, 0);
if (foo) {
fprintf(stderr, "%s : err %d on save_as_pnm\n", __func__, foo);
exit(1);
}
fimg_destroy(&gray);
return 0;
}
/* ---------------------------------------------------------------- */
int essai_clone_et_copy(int unused)
{
FloatImg A, B, C;
int foo;
foo = fimg_create(&A, 512, 512, FIMG_TYPE_RGB);
if (foo) {
fprintf(stderr, "%s err create A %d\n", __func__, foo);
return foo;
}
foo = fimg_draw_something(&A);
if (foo) {
fprintf(stderr, "%s err drawing A %d\n", __func__, foo);
return foo;
}
foo = fimg_save_as_pnm(&A, "A.pnm", 0);
if (foo) {
fprintf(stderr, "%s : err %d on save_as_pnm\n", __func__, foo);
exit(1);
}
foo = fimg_clone(&A, &B, 1);
if (foo) {
fprintf(stderr, "%s err clone B %d\n", __func__, foo);
return foo;
}
foo = fimg_create(&C, 512, 512, FIMG_TYPE_RGB);
if (foo) {
fprintf(stderr, "%s err create A %d\n", __func__, foo);
return foo;
}
foo = fimg_copy_data(&A, &C);
if (foo) {
fprintf(stderr, "%s err copydata %d\n", __func__, foo);
return foo;
}
foo = fimg_save_as_pnm(&C, "C.pnm", 0);
return 0;
}
/* ---------------------------------------------------------------- */
int essai_contraste(char *fname)
{
int foo;
FloatImg dessin, copy;
double maxi;
foo = fimg_create_from_dump(fname, &dessin);
foo = fimg_clone(&dessin, &copy, 0);
maxi = (double)fimg_get_maxvalue(&dessin);
fprintf(stderr, "image source valeur maxi = %f\n", maxi);
fimg_power_2(&dessin, &copy, maxi);
maxi = (double)fimg_get_maxvalue(&copy);
fprintf(stderr, "apres power_2 valeur maxi = %f\n", maxi);
fimg_dump_to_file(&copy, "power2.fimg", 0);
fimg_square_root(&dessin, &copy, maxi);
maxi = (double)fimg_get_maxvalue(&copy);
fprintf(stderr, "apres square_root valeur maxi = %f\n", maxi);
fimg_dump_to_file(&copy, "squareroot.fimg", 0);
fimg_cos_01(&dessin, &copy, maxi);
maxi = (double)fimg_get_maxvalue(&copy);
fprintf(stderr, "apres cos 01 valeur maxi = %f\n", maxi);
fimg_dump_to_file(&copy, "cos_01.fimg", 0);
fimg_cos_010(&dessin, &copy, maxi);
maxi = (double)fimg_get_maxvalue(&copy);
fprintf(stderr, "apres cos 010 valeur maxi = %f\n", maxi);
fimg_dump_to_file(&copy, "cos_010.fimg", 0);
fimg_destroy(&dessin);
return -1;
}
/* ---------------------------------------------------------------- */
#define W 320
#define H 240
int main(int argc, char *argv[])
{
int foo, opt;
// char outname[100];
int gray = 0;
while ((opt = getopt(argc, argv, "gn:v")) != -1) {
switch(opt) {
case 'g': gray++; break;
case 'n': foo=atoi(optarg); break;
case 'v': verbosity++; break;
}
}
if (verbosity) fimg_print_version(0);
foo = essai_normalize();
fprintf(stderr, "retour essai normalize -> %d\n", foo);
return 0;
}