"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/morphology_int.c" between
sip-0.5.6.tar.gz and sip-0.12.1.tar.gz

About: SIP (Scilab Image Processing) toolbox to do imaging tasks such as filtering, blurring, edge detection, thresholding, histogram manipulation, segmentation, mathematical morphology, color image processing, etc.

morphology_int.c  (sip-0.5.6):morphology_int.c  (sip-0.12.1)
skipping to change at line 29 skipping to change at line 29
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
*/ */
#include <stack-c.h> #include <stack-c.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <animal/animal.h> #include <animal/animal.h>
#include "sip_common.h" #include "sip_common.h"
/*---------------------------------------------------------- /*----------------------------------------------------------
* [img]=edilate(img [, radius, opt, pad]) * [img]=edilate(img [, radius, opt, pad, method])
* radius defaults to 5 * radius defaults to 5
* opt is "full" if result is not trimmed * opt is "full" if result is not trimmed
* opt is "same" if result is trimmed to original size * opt is "same" if result is trimmed to original size
* @@@@@@@@@ * @@@@@@@@@
* TODO * TODO
* - use IFT fast euclidean propagation * - use IFT fast euclidean propagation
* - work with integers * - work with integers
* - interface must be similar to matlab * - interface must be similar to matlab
* - fazer opcao: pad/unpad? como matlab faz isto? * - fazer opcao: pad/unpad? como matlab faz isto?
*----------------------------------------------------------*/ *----------------------------------------------------------*/
#define MAX_OPT 10 #define MAX_OPT 10
SipExport int SipExport int
edilate_int(char *fname) edilate_int(char *fname)
{ {
/* Interface variables */ /* Interface variables */
int r1, c1, p1, int r1, c1, p1,
r2, c2, p2, r2, c2, p2,
r3, c3, p3, r3, c3, p3,
r_alg, c_alg, l_alg,
ro, co, ro, co,
i, irad, i, irad,
nv=1, nv=1,
minlhs=1, maxlhs=1, minrhs=1, maxrhs=3; minlhs=1, maxlhs=1, minrhs=1, maxrhs=4;
Img *im, *result, *tmp; ImgPUInt32 *im, *tmp;
Img *im_int, *result, *tmp_int;
double *po, radius=5; double *po, radius=5;
char opt[MAX_OPT]="same"; char opt[MAX_OPT]="same", *str;
bool stat; bool stat;
dt_algorithm alg=DT_CUISENAIRE_PMN_1999;
CheckRhs(minrhs,maxrhs); CheckRhs(minrhs,maxrhs);
CheckLhs(minlhs,maxlhs); CheckLhs(minlhs,maxlhs);
GetRhsVar(nv++, "d", &r1, &c1, &p1); // img GetRhsVar(nv++, "d", &r1, &c1, &p1); // img
if (Rhs == 2) { if (Rhs == 2) {
GetRhsVar(nv++, "d", &r2, &c2, &p2); // radius GetRhsVar(nv++, "d", &r2, &c2, &p2); // radius
radius = *stk(p2); radius = *stk(p2);
} else if (Rhs == 3) { } else if (Rhs >= 3) {
GetRhsVar(nv++, "d", &r2, &c2, &p2); // radius GetRhsVar(nv++, "d", &r2, &c2, &p2); // radius
radius = *stk(p2); radius = *stk(p2);
GetRhsVar(nv++, "c", &r3, &c3, &p3); // opt GetRhsVar(nv++, "c", &r3, &c3, &p3); // opt
strncpy(opt,cstk(p3),MAX_OPT); strncpy(opt,cstk(p3),MAX_OPT);
if (Rhs == 4) {
GetRhsVar(nv++, "c", &r_alg, &c_alg, &l_alg);
str = cstk(l_alg);
if ( strncasecmp("exact dilations",str,8) == 0 ||
strcmp("costa-estrozi",str) == 0)
alg=DT_EXACT_DILATIONS;
else if (strcasecmp("cuisenaire pmn",str) == 0)
alg=DT_CUISENAIRE_PMN_1999;
else
sip_error("invalid second argument -- unknown method"
);
}
} }
/* @@@ maybe there's a better way of passing data */ if (alg == DT_EXACT_DILATIONS) {
im=new_img(c1, r1); /* @@@ maybe there's a better way of passing data */
if (!im) sip_error("unable to alloc memory"); im_int=new_img(c1, r1);
sci_2D_double_matrix_to_animal(p1,r1,c1,im,pixval,1); if (!im_int) sip_error("unable to alloc memory");
sci_2D_double_matrix_to_animal(p1,r1,c1,im_int,pixval,1);
irad = (int) ceil(radius);
result = new_img(im->rows+2*irad, im->cols+2*irad); irad = (int) ceil(radius);
if (!result) sip_error("unable to alloc memory"); result = new_img(im_int->rows+2*irad, im_int->cols+2*irad);
if (!result) sip_error("unable to alloc memory");
edilate_np(result,im,radius);
edilate_np(result,im_int,radius);
if (strcmp(opt,"same") == 0) {
tmp = result; if (strcmp(opt,"same") == 0) {
result = imtrim (result, irad, irad); tmp_int = result;
imfree (&tmp); result = imtrim (result, irad, irad);
imfree (&tmp_int);
}
imfree(&im_int);
im_int = result;
ro=im_int->cols; co=im_int->rows;
stat = animal_grayscale_image_to_double_array(fname, im_int, &po);
if (!stat) return false;
imfree(&im_int);
} else { /* Fast exact Euclidean propagation algorithm */
/* @@@ maybe there's a better way of passing data */
im = new_img_puint32(c1, r1);
if (!im) sip_error("unable to alloc memory");
sci_2D_double_matrix_to_animal(p1,r1,c1,im,pixval,1);
for (i=0; i<r1*c1; ++i)
DATA(im)[i] = (PROUND(pixval,*stk(p1+i)) == 0);
im->isbinary = true;
if (strcmp(opt,"same") != 0) {
irad = (int) ceil(radius);
tmp = impad_puint32(im, irad, irad, 1);
if (!tmp) sip_error("unable to alloc memory");
imfree_puint32(&im);
im = tmp;
}
stat = distance_transform_ip_max_dist(im, alg, (int)ceil(radius*radius), fa
lse, NULL);
if (!stat) return false; /* @@@ garbage collection */
ro=im->cols; co=im->rows;
for (i = 0; i <ro*co; i++)
im->data[i] = (im->data[i] <= radius*radius);
im->isbinary = true;
stat = animal_grayscale_imgpuint32_to_double_array(fname, im, &po);
if (!stat) return false;
imfree_puint32(&im);
} }
imfree(&im);
im = result;
ro=im->cols; co=im->rows;
stat = animal_grayscale_image_to_double_array(fname, im, &po);
if (!stat) return false;
imfree(&im);
CreateVarFromPtr(nv, "d", &ro, &co, &po); CreateVarFromPtr(nv, "d", &ro, &co, &po);
/* Return variables */ /* Return variables */
LhsVar(1) = nv; LhsVar(1) = nv;
free(po); free(po);
return true; return true;
} }
 End of changes. 9 change blocks. 
27 lines changed or deleted 78 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS