Changeset 4815 for trunk/psLib/src/imageops
- Timestamp:
- Aug 18, 2005, 11:44:40 AM (21 years ago)
- Location:
- trunk/psLib/src/imageops
- Files:
-
- 4 edited
-
psImageConvolve.c (modified) (4 diffs)
-
psImageConvolve.h (modified) (2 diffs)
-
psImagePixelManip.c (modified) (2 diffs)
-
psImagePixelManip.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageConvolve.c
r4544 r4815 5 5 * @author Robert DeSonia, MHPCC 6 6 * 7 * @version $Revision: 1.2 2$ $Name: not supported by cvs2svn $8 * @date $Date: 2005-0 7-12 19:33:49$7 * @version $Revision: 1.23 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2005-08-18 21:44:40 $ 9 9 * 10 10 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 12 12 13 13 #include <string.h> 14 14 #include <math.h> 15 15 #include "psImageConvolve.h" 16 16 #include "psImageFFT.h" … … 279 279 } 280 280 281 psImage* psImageConvolve(psImage* out, const psImage* in, const psKernel* kernel, bool direct) 281 psImage* psImageConvolve(psImage* out, 282 const psImage* in, 283 const psKernel* kernel, 284 bool direct) 282 285 { 283 286 if (in == NULL) { … … 476 479 return out; 477 480 } 481 482 void psImageSmooth (psImage *image, 483 float sigma, 484 float Nsigma) 485 { 486 487 int Nx, Ny, Npixel, Nrange; 488 float factor, g, s; 489 psVector *temp; 490 491 // relevant terms 492 Nrange = sigma*Nsigma + 0.5; 493 Npixel = 2*Nrange + 1; 494 factor = -0.5/(sigma*sigma); 495 496 Nx = image->numCols; 497 Ny = image->numRows; 498 499 // generate gaussian 500 psVector *gaussnorm = psVectorAlloc (Npixel, PS_TYPE_F32); 501 for (int i = -Nrange; i < Nrange + 1; i++) { 502 gaussnorm->data.F32[i+Nrange] = exp (factor*i*i); 503 } 504 psF32 *gauss = &gaussnorm->data.F32[Nrange]; 505 506 // smooth in X direction 507 temp = psVectorAlloc (Nx, PS_TYPE_F32); 508 for (int j = 0; j < Ny; j++) { 509 psF32 *vi = image->data.F32[j]; 510 psF32 *vo = temp->data.F32; 511 for (int i = 0; i < Nx; i++) { 512 g = s = 0; 513 for (int n = -Nrange; n < Nrange + 1; n++) { 514 if (i+n < 0) 515 continue; 516 if (i+n >= Nx) 517 continue; 518 s += gauss[n]*vi[i+n]; 519 g += gauss[n]; 520 } 521 vo[i] = s / g; 522 } 523 memcpy (image->data.F32[j], temp->data.F32, Nx*sizeof(psF32)); 524 } 525 psFree (temp); 526 527 // smooth in Y direction 528 temp = psVectorAlloc (image->numRows, PS_TYPE_F32); 529 for (int i = 0; i < Nx; i++) { 530 psF32 *vo = temp->data.F32; 531 psF32 **vi = image->data.F32; 532 for (int j = 0; j < Ny; j++) { 533 g = s = 0; 534 for (int n = -Nrange; n < Nrange + 1; n++) { 535 if (j+n < 0) 536 continue; 537 if (j+n >= Ny) 538 continue; 539 s += gauss[n]*vi[j+n][i]; 540 g += gauss[n]; 541 } 542 vo[j] = s / g; 543 } 544 // replace temp in image 545 for (int j = 0; j < Ny; j++) { 546 vi[j][i] = vo[j]; 547 } 548 } 549 psFree (temp); 550 psFree (gaussnorm); 551 } 552 -
trunk/psLib/src/imageops/psImageConvolve.h
r4540 r4815 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1. 9$ $Name: not supported by cvs2svn $10 * @date $Date: 2005-0 7-12 19:12:01$9 * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2005-08-18 21:44:40 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 126 126 ); 127 127 128 /** Smooths an image by parts using 1D Gaussian independently in x and y. 129 * 130 * Applies a circularly symmetric Gaussian smoothing first in x and then in y 131 * directions with just a vector. This process is 2N faster than 2D convolutions (in general). 132 */ 133 void psImageSmooth( 134 psImage *image, ///< the image to be smoothed 135 float sigma, ///< the width of the smoothing kernel in pixels 136 float Nsigma ///< the size of the smoothing box in sigmas 137 ); 138 139 128 140 #endif // #ifndef PS_IMAGE_CONVOLVE_H -
trunk/psLib/src/imageops/psImagePixelManip.c
r4589 r4815 10 10 * @author Ross Harman, MHPCC 11 11 * 12 * @version $Revision: 1. 7$ $Name: not supported by cvs2svn $13 * @date $Date: 2005-0 7-21 01:40:10 $12 * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2005-08-18 21:44:40 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 396 396 } 397 397 398 // mask the area contained by the region 399 // the region is defined wrt the parent image 400 void psImageMaskRegion(psImage *image, 401 psRegion *region, 402 bool logical_and, 403 int maskValue) 404 { 405 406 for (int iy = 0; iy < image->numRows; iy++) { 407 for (int ix = 0; ix < image->numCols; ix++) { 408 if (ix + image->col0 < region->x0) 409 continue; 410 if (ix + image->col0 >= region->x1) 411 continue; 412 if (iy + image->row0 < region->y0) 413 continue; 414 if (iy + image->row0 >= region->y1) 415 continue; 416 if (logical_and) { 417 image->data.U8[iy][ix] &= maskValue; 418 } else { 419 image->data.U8[iy][ix] |= maskValue; 420 } 421 } 422 } 423 } 424 425 // mask the area not contained by the region 426 // the region is defined wrt the parent image 427 void psImageKeepRegion(psImage *image, 428 psRegion *region, 429 bool logical_and, 430 int maskValue) 431 { 432 433 for (int iy = 0; iy < image->numRows; iy++) { 434 for (int ix = 0; ix < image->numCols; ix++) { 435 if (ix + image->col0 < region->x0) 436 goto maskit; 437 if (ix + image->col0 >= region->x1) 438 goto maskit; 439 if (iy + image->row0 < region->y0) 440 goto maskit; 441 if (iy + image->row0 >= region->y1) 442 goto maskit; 443 continue; 444 maskit: 445 if (logical_and) { 446 image->data.U8[iy][ix] &= maskValue; 447 } else { 448 image->data.U8[iy][ix] |= maskValue; 449 } 450 } 451 } 452 } 453 454 // mask the area contained by the region 455 // the region is defined wrt the parent image 456 void psImageMaskCircle(psImage *image, 457 double x, 458 double y, 459 double radius, 460 bool logical_and, 461 int maskValue) 462 { 463 464 double dx, dy, r2, R2; 465 466 R2 = PS_SQR(radius); 467 468 for (int iy = 0; iy < image->numRows; iy++) { 469 for (int ix = 0; ix < image->numCols; ix++) { 470 dx = ix + image->col0 - x; 471 dy = iy + image->row0 - y; 472 r2 = PS_SQR(dx) + PS_SQR(dy); 473 if (r2 > R2) 474 continue; 475 if (logical_and) { 476 image->data.U8[iy][ix] &= maskValue; 477 } else { 478 image->data.U8[iy][ix] |= maskValue; 479 } 480 } 481 } 482 } 483 484 // mask the area contained by the region 485 // the region is defined wrt the parent image 486 void psImageKeepCircle(psImage *image, 487 double x, 488 double y, 489 double radius, 490 bool logical_and, 491 int maskValue) 492 { 493 494 double dx, dy, r2, R2; 495 496 R2 = PS_SQR(radius); 497 498 for (int iy = 0; iy < image->numRows; iy++) { 499 for (int ix = 0; ix < image->numCols; ix++) { 500 dx = ix + image->col0 - x; 501 dy = iy + image->row0 - y; 502 r2 = PS_SQR(dx) + PS_SQR(dy); 503 if (r2 < R2) 504 continue; 505 if (logical_and) { 506 image->data.U8[iy][ix] &= maskValue; 507 } else { 508 image->data.U8[iy][ix] |= maskValue; 509 } 510 } 511 } 512 } 513 -
trunk/psLib/src/imageops/psImagePixelManip.h
r4589 r4815 8 8 * @author Robert DeSonia, MHPCC 9 9 * 10 * @version $Revision: 1. 8$ $Name: not supported by cvs2svn $11 * @date $Date: 2005-0 7-21 01:40:10 $10 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2005-08-18 21:44:40 $ 12 12 * 13 13 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 87 87 const char *op ///< the operation to perform for overlay 88 88 ); 89 /** Sets the bits inside the region, ignoring pixels outside. 90 * 91 * The pixels are set by combining the existing pixel value and the given maskValue 92 * with a logical operation. The allowed operations are =, AND, OR, and XOR. 93 */ 94 void psImageMaskRegion( 95 psImage *image, ///< the image to set 96 psRegion *region, ///< the specified region 97 bool logical_and, ///< the logical operation 98 int maskValue ///< the specified bits 99 ); 100 101 /** Sets the bits outside the region, ignoring pixels inside. 102 * 103 * The pixels are set by combining the existing pixel value and the given maskValue 104 * with a logical operation. The allowed operations are =, AND, OR, and XOR. 105 */ 106 void psImageKeepRegion( 107 psImage *image, ///< the image to set 108 psRegion *region, ///< the specified region 109 bool logical_and, ///< the logical operation 110 int maskValue ///< the specified bits 111 ); 112 113 /** Sets the bits inside the circle, ignoring the pixels outside. 114 * 115 * The pixel values are set by combining the existing pixel value and the given maskValue 116 * with a logical operation. The allowed operations are =, AND, OR, and XOR. 117 */ 118 void psImageMaskCircle( 119 psImage *image, ///< the image to set 120 double x, ///< the x coordinate of the circle's center 121 double y, ///< the y coordinate of the circle's center 122 double radius, ///< the radius of the specified circle 123 bool logical_and, ///< the logical operation 124 int maskValue ///< the specified bits 125 ); 126 127 /** Sets the bits outside the circle, ignoring the pixels inside. 128 * 129 * The pixel values are set by combining the existing pixel value and the given maskValue 130 * with a logical operation. The allowed operations are =, AND, OR, and XOR. 131 */ 132 void psImageKeepCircle( 133 psImage *image, ///< the image to set 134 double x, ///< the x coordinate of the circle's center 135 double y, ///< the y coordinate of the circle's center 136 double radius, ///< the radius of the specified circle 137 bool logical_and, ///< the logical operation 138 int maskValue ///< the specified bits 139 ); 89 140 90 141 #endif // #ifndef PS_IMAGE_PIXEL_MANIP_H
Note:
See TracChangeset
for help on using the changeset viewer.
