TPCCLIB
Loading...
Searching...
No Matches
circle.c File Reference

Functions for simulating circular image region. More...

#include "libtpcidi.h"

Go to the source code of this file.

Functions

int imgCircleMask (IMG *img, int zi, double cx, double cy, double r, double mv, double *smv, int verbose)
int imgRingMask (IMG *img, int zi, double cx, double cy, double r1, double r2, double mv, double *smv, int verbose)

Detailed Description

Functions for simulating circular image region.

Author
Vesa Oikonen

Definition in file circle.c.

Function Documentation

◆ imgCircleMask()

int imgCircleMask ( IMG * img,
int zi,
double cx,
double cy,
double r,
double mv,
double * smv,
int verbose )

Simulate a mask image of circle with specified radius.

The applied method is only approximate at pixel borders (pixel is divided into 5x5 subpixels).

See also
imgRingMask, imgSimulateSphere, idiSimulateTubeVol, imgMaskInvert
Returns
Returns 0 if successful.
Parameters
imgPointer to allocated static or dynamic image; image must contain pixel sizes and dimensions; mask values are added to pixel values, thus you may need to set pixel values to zero before calling this function.
ziPlane index [0..dimz-1].
cxX distance of circle centre (mm) from the upper left corner of the image.
cyY distance of circle centre (mm) from the upper left corner of the image.
rRadius of circle (mm).
mvMask value; this value is added to each pixel value that fits inside the radius; the pixels that are partially inside the radius will get fraction of mask value.
smvPointer to value where the sum of added mask pixel values is written; enter NULL if not needed. Use this to validate the results.
verboseVerbose level; set to <=0 to prevent all prints to stdout.

Definition at line 16 of file circle.c.

37 {
38 if(verbose>0) printf("%s(img, %d, %g, %g, %g, %g, ...)\n", __func__, zi, cx, cy, r, mv);
39
40 int n, xi, yi, fi, i, j;
41 double dx[5], dy[5], r2, v;
42
43 if(img->status<IMG_STATUS_OCCUPIED) return(1);
44 if(zi<0 || zi>=img->dimz) return(2);
45 if(img->sizey<=0.0 || img->sizex<=0.0) return(3);
46 if(img->sizey!=img->sizex) return(4);
47 if(img->dimt<1) return(5);
48
49 if(smv!=NULL) *smv=0.0;
50 /* Compare r^2 to sum of squared distances instead of square root */
51 r2=r*r;
52 for(yi=0; yi<img->dimy; yi++) {
53 dy[0]=(0.1+(double)yi)*img->sizey - cy;
54 for(j=1; j<5; j++) dy[j]=dy[j-1]+0.2*img->sizey;
55 for(xi=0; xi<img->dimx; xi++) {
56 dx[0]=(0.1+(double)xi)*img->sizex - cx;
57 for(i=1; i<5; i++) dx[i]=dx[i-1]+0.2*img->sizex;
58 for(i=0, n=0; i<5; i++) for(j=0; j<5; j++) if((dx[i]*dx[i]+dy[j]*dy[j])<r2) n++;
59 if(n==0) continue;
60 v=(double)n*mv/25.0;
61 for(fi=0; fi<img->dimt; fi++) img->m[zi][yi][xi][fi]+=v;
62 if(smv!=NULL) *smv+=v;
63 }
64 }
65
66 return(0);
67}
#define IMG_STATUS_OCCUPIED
float sizex
unsigned short int dimx
float **** m
char status
unsigned short int dimt
float sizey
unsigned short int dimz
unsigned short int dimy

Referenced by imgRingMask().

◆ imgRingMask()

int imgRingMask ( IMG * img,
int zi,
double cx,
double cy,
double r1,
double r2,
double mv,
double * smv,
int verbose )

Simulate a mask image of ring with specified inner and outer radius.

The applied method is only approximate at pixel borders (pixel is divided into 5x5 subpixels).

See also
imgCircleMask, imgSimulateRing, imgSimulateSphere, imgMaskInvert
Returns
Returns 0 if successful.
Parameters
imgPointer to allocated static or dynamic image; image must contain pixel sizes and dimensions; mask values are added to pixel values, thus you may need to set pixel values to zero before calling this function.
ziPlane index [0..dimz-1].
cxX distance of circle centre (mm) from the upper left corner of the image.
cyY distance of circle centre (mm) from the upper left corner of the image.
r1Inner radius of circle (mm).
r2Outer radius of circle (mm).
mvMask value; this value is added to each pixel value that fits inside the radius; the pixels that are partially inside the radius will get fraction of mask value.
smvPointer to value where the sum of added mask pixel values is written; enter NULL if not needed. Use this to validate the results.
verboseVerbose level; set to <=0 to prevent all prints to stdout.

Definition at line 77 of file circle.c.

100 {
101 int ret;
102 double mv1, mv2, d;
103
104 if(verbose>0) printf("%s(img, %d, %g, %g, %g, %g, %g, ...)\n", __func__, zi, cx, cy, r1, r2, mv);
105 if(r1>=r2 || r1<0.0) {
106 if(verbose>0) fprintf(stderr, "Error: invalid radius.\n");
107 return(1);
108 }
109
110 /* Simulate circle with the larger radius */
111 ret=imgCircleMask(img, zi, cx, cy, r2, mv, &mv1, verbose);
112 if(ret!=0) {
113 if(verbose>0) fprintf(stderr, "Error: cannot simulate circle 1.\n");
114 return(ret);
115 }
116 /* Subtract circle with the smaller radius */
117 ret=imgCircleMask(img, zi, cx, cy, r1, -mv, &mv2, verbose);
118 if(ret!=0) {
119 if(verbose>0) fprintf(stderr, "Error: cannot simulate circle 2.\n");
120 return(ret);
121 }
122 /* Calculate the sum of mask pixel values */
123 d=mv1+mv2; if(smv!=NULL) *smv=d;
124 if(d==0.0 && verbose>0) {fprintf(stderr, "Warning: empty mask image created.\n"); fflush(stderr);}
125 return(0);
126}
int imgCircleMask(IMG *img, int zi, double cx, double cy, double r, double mv, double *smv, int verbose)
Definition circle.c:16