//1999-02-09,鲍捷,浮雕效果 //只对灰度图像有效 BOOL VPicEx::TrueEmboss() { if( !IsValid() ) return FALSE; imgdes *srcimg=GetImgDes(); // colortogray(srcimg,srcimg); imgdes image1; imgdes image2; imgdes tmpsrc; int cols, rows, rcode; char kern1[10] = {-2,-2,0,-2,6,0,0,0,0,1}; char kern2[10] = {0,0,0,0,-6,2,0,2,2,1}; cols = CALC_WIDTH(srcimg); rows = CALC_HEIGHT(srcimg); allocimage(&tmpsrc, cols, rows, 8); // Assumes 8-bit source image copyimage(srcimg, &tmpsrc); allocimage(&image1, cols, rows, 8); allocimage(&image2, cols, rows, 8); matrixconv(kern1, &tmpsrc, &image1); matrixconv(kern2, &tmpsrc, &image2); zeroimage(128, &tmpsrc); addimage(&tmpsrc, &image1, &tmpsrc); subimage(&tmpsrc, &image2, &tmpsrc); rcode = copyimage(&tmpsrc, srcimg); // Assumes 8-bit result image freeimage(&image2); freeimage(&image1); freeimage(&tmpsrc); return(rcode == NO_ERROR); }
//1999-02-18,鲍捷,胶粒效果 BOOL VPicEx::Pointillistic() { imgdes *srcimg=GetImgDes(); imgdes tmpsrc, tmp8; int cols, rows, rcode; static char kern1[10] = {0,-1,0,-1,5,-1,0,-1,0,1}; cols = CALC_WIDTH(srcimg); rows = CALC_HEIGHT(srcimg); allocimage(&tmpsrc, cols, rows, 24); allocimage(&tmp8, cols, rows, 8); if(srcimg->bmh->biBitCount == 8) { convertpaltorgb(srcimg, &tmpsrc); } else { copyimage(srcimg, &tmpsrc); } removenoise(&tmpsrc, &tmpsrc); convertrgbtopalex(200, &tmpsrc, &tmp8, CR_OCTREEDIFF); convertpaltorgb(&tmp8, &tmpsrc); freeimage(&tmp8); matrixconv(kern1, &tmpsrc, &tmpsrc); if(srcimg->bmh->biBitCount == 8) { rcode = convertrgbtopal(256, &tmpsrc, srcimg); } else { rcode = copyimage(&tmpsrc, srcimg); } freeimage(&tmpsrc); return(rcode == NO_ERROR); }
//1999-02-19,鲍捷,阴影效果 BOOL VPicEx::DropShadow() { imgdes *srcimg=GetImgDes(); imgdes tmpsrc, tmpmask; int rcode = NO_ERROR, j, shadow_width=20, shadow_height=20, cols, rows; cols = CALC_WIDTH(srcimg); rows = CALC_HEIGHT(srcimg); allocimage(&tmpsrc, cols, rows, srcimg->bmh->biBitCount); allocimage(&tmpmask, cols, rows, srcimg->bmh->biBitCount); zeroimage(255, &tmpsrc); tmpsrc.stx=shadow_width; tmpsrc.sty=shadow_width; copyimage(srcimg, &tmpsrc); tmpsrc.stx = 0; tmpsrc.sty = 0; kodalith(230, &tmpsrc, &tmpsrc);//二值化,门限230 //门限以上的像素被认为白色,不产生阴影 negative(&tmpsrc, &tmpmask); changebright(128, &tmpsrc, &tmpsrc); for(j=0; j<10; j++) blur(&tmpsrc, &tmpsrc); //使阴影模糊。循环越多越模糊,扩散越大 tmpmask.stx=shadow_width; tmpmask.sty=shadow_width; addimage(&tmpsrc, &tmpmask, &tmpsrc); andimage(srcimg, &tmpsrc, srcimg); freeimage(&tmpmask); freeimage(&tmpsrc); return(rcode == NO_ERROR); }
int main(int argc, char **argv) // argv are the command-line arguments { char infname[512], outfname[512]; // file names for input and output unsigned char imagetypein, imagetypeout; IMAGE *data; IMAGE *target; if(argc<5) // too few command-line arguments? { printf("Command-line usage:\n"); printf(" %s (inf) (outf) (x) (y)\n",argv[0]); printf(" (inf) is the input file name\n"); printf(" (outf) is the output file name\n"); printf(" (x), (y) are the image dimensions\n"); exit(0); } // Allocate local memory for struct pointers data = malloc(sizeof(IMAGE)); // Handle Command Line args strcpy(infname,nextargs); // read input file name strcpy(outfname,nextargs); // read output file name data->xmax = nextargi; // Read image dimensions data->ymax = nextargi; //data->zmax = nextargi; data->zmax = 1; // params set image data types in and out imagetypein = UCHARIMAGE; imagetypeout = FLOATIMAGE; // Read Image into Mem printf("Reading image %s with dimensions %d, %d, %d\n",infname,data->xmax,data->ymax,data->zmax); if(read_raw(infname, data)){ printf("Error reading file\n"); exit (1); } // Set target params, Allocate local memory target = malloc(sizeof(IMAGE)); if(copyimage(target, data, imagetypeout)){ fprintf(stderr,"Could not Create Image: target\n"); exit(-1); } /* Image Processing calls here */ printf(" Converting Data Types...\n"); //switch case with command line parameters to specify data type conversions if(uchar2float(target, data)){ printf("Error Converting\n"); exit(3); } // Write Image to File printf("Writing processed image %s with dimensions %d, %d, %d\n",outfname,target->xmax,target->ymax,target->zmax); if(write_raw(outfname, target)){ printf("Error writing file\n"); exit (4); } // Free All Memory removeimage(data,imagetypein); removeimage(target,imagetypeout); printf("Program completed successfully\n"); exit (0); }
/* 水彩效果平滑图像的不规则部分,然后强调色彩边界 (grayscale or color image, 8- or 24-bit. ) */ BOOL VPicEx::WaterColor() { imgdes *srcimg=GetImgDes(); imgdes tmpsrc; int cols, rows, rcode; double gamma = 0.7; cols = CALC_WIDTH(srcimg); rows = CALC_HEIGHT(srcimg); allocimage(&tmpsrc, cols, rows, srcimg->bmh->biBitCount); copyimage(srcimg, &tmpsrc); gammabrighten(gamma, &tmpsrc, &tmpsrc); removenoise(&tmpsrc, &tmpsrc); removenoise(&tmpsrc, &tmpsrc); removenoise(&tmpsrc, &tmpsrc); sharpen(&tmpsrc, &tmpsrc); rcode = copyimage(&tmpsrc, srcimg); freeimage(&tmpsrc); return(rcode == NO_ERROR); }
int main(int argc, char **argv) // argv are the command-line arguments { char infname[512], outfname[512]; // file names for input and output IMAGE *data; IMAGE *target; if(argc<5) // too few command-line arguments? { printf("Command-line usage:\n"); printf(" %s (inf) (outf) (x) (y)\n",argv[0]); printf(" (inf) is the input file name\n"); printf(" (outf) is the output file name\n"); printf(" (x), (y) are the image dimensions\n"); //printf(" (x), (y), (z) are the image dimensions\n"); exit(0); } // Allocate local memory for struct pointers data = malloc(sizeof(IMAGE)); // Handle Command Line args strcpy(infname,nextargs); // read input file name strcpy(outfname,nextargs); // read output file name data->xmax = nextargi; // Read image dimensions data->ymax = nextargi; data->zmax = 1; //nextargi; // Read Image, Allocate Img mem printf("Reading image %s with dimensions %d, %d, %d\n",infname,data->xmax,data->ymax,data->zmax); if(read_raw(infname, data)){ printf("Error reading file\n"); exit (1); } // Set target params, Allocate local memory target = malloc(sizeof(IMAGE)); if(copyimage(target, data)){ fprintf(stderr,"Could not Create Image: target\n"); exit(-1); } /* Image Processing calls here */ printf(" Drawing AutoStereogram...\n"); if(heightmap(data)){ printf("Error Making Height Map\n"); exit(3); } if(DrawAutoStereogram(target, data)){ printf("Error Generating SIRDS\n"); exit(3); } // Write Image printf("Writing processed image %s with dimensions %d, %d, %d\n",outfname,target->xmax,target->ymax,target->zmax); if(write_raw(outfname, target)){ printf("Error writing file\n"); exit (4); } // Free All Memory removeimage(data); removeimage(target); printf("Program completed successfully\n"); exit (0); }
//1999-02-18,鲍捷,快速浮雕效果 //只对灰度图像有效 BOOL VPicEx::QuickEmboss() { imgdes *srcimg=GetImgDes(); imgdes image1; imgdes tmpsrc; int cols, rows, rcode; cols = CALC_WIDTH(srcimg); rows = CALC_HEIGHT(srcimg); allocimage(&tmpsrc, cols, rows, 8); copyimage(srcimg, &tmpsrc); allocimage(&image1, cols, rows, 8); negative(&tmpsrc, &image1); image1.stx = 1; image1.sty = 1; wtaverage(50, &tmpsrc, &image1, &tmpsrc); expandcontrast(100, 155, &tmpsrc, &tmpsrc); rcode = copyimage(&tmpsrc, srcimg); freeimage(&image1); freeimage(&tmpsrc); return(rcode == NO_ERROR); }
/* =============================================================== */ int32_t l3dboundary(struct xvimage * f) /* =============================================================== */ /* extrait la frontière interne def: {x in F | theta(x) inter Fbar neq emptyset} */ { #undef F_NAME #define F_NAME "l3dboundary" struct xvimage * g; index_t rs, cs, ds, ps, N; index_t x, y, z; uint8_t *F; uint8_t *G; index_t tab[26]; int32_t n, u; rs = rowsize(f); cs = colsize(f); ds = depth(f); F = UCHARDATA(f); ps = rs * cs; N = ps * ds; g = copyimage(f); if (g == NULL) { fprintf(stderr,"%s: copyimage failed\n", F_NAME); return 0; } G = UCHARDATA(g); memset(F, 0, N); for (z = 0; z < ds; z++) for (y = 0; y < cs; y++) for (x = 0; x < rs; x++) if (G[z*ps + y*rs + x]) { Thetacarre3d(rs, cs, ds, x, y, z, tab, &n); for (u = 0; u < n; u++) if (G[tab[u]] == 0) { F[z*ps + y*rs + x] = NDG_MAX; goto next; } next:; } freeimage(g); return 1; } /* l3dboundary() */
/* =============================================================== */ int32_t ltuf(struct xvimage * image, int32_t connexmin, int32_t rayon) /* =============================================================== */ #undef F_NAME #define F_NAME "ltuf" { struct xvimage * copy; int32_t rs, cs, ds, ps, N; int32_t ndes; rs = rowsize(image); /* taille ligne */ cs = colsize(image); /* taille colonne */ ps = rs * cs; /* taille plan */ ds = depth(image); /* nombre plans */ N = ds * ps; /* taille image */ if (ds == 1) /* ======================= 2D ========================*/ { copy = copyimage(image); if (copy == NULL) { fprintf(stderr, "%s: copyimage failed\n", F_NAME); return 0; } do { if (! lhthindelta(image, NULL, rayon, connexmin)) { fprintf(stderr, "%s: lhthindelta failed\n", F_NAME); return 0; } ndes = p_despics(image, connexmin); if (! lhtkernu(image, copy, connexmin)) { fprintf(stderr, "%s: lhtkernu failed\n", F_NAME); return 0; } if (ndes) memcpy(UCHARDATA(copy), UCHARDATA(image), N); } while (ndes); } else /* ============================== 3D ================================*/ { fprintf(stderr, "%s: 3D Not Yet Implemented\n", F_NAME); return 0; } freeimage(copy); return 1; } /* ltuf() */
static void function2 (struct _file_ * file, signed index, flag_t flags) { static signed image = 0; static signed origin = ~0; static signed offset = 0; struct nvm_header2 nvm_header; if (read (file->file, &nvm_header, sizeof (nvm_header)) != sizeof (nvm_header)) { error (1, errno, NVM_HDR_CANTREAD, file->name, image); } if (LE16TOH (nvm_header.MajorVersion) != 1) { error (1, 0, NVM_HDR_VERSION, file->name, image); } if (LE16TOH (nvm_header.MinorVersion) != 1) { error (1, 0, NVM_HDR_VERSION, file->name, image); } if (checksum32 (&nvm_header, sizeof (nvm_header), 0)) { error (1, 0, NVM_HDR_CHECKSUM, file->name, image); } if (~nvm_header.PrevHeader) { error (1, 0, NVM_HDR_LINK, file->name, image); } if (~nvm_header.NextHeader) { error (1, 0, NVM_HDR_LINK, file->name, image); } nvm_header.PrevHeader = HTOLE32 (origin); origin = offset; if (index) { offset += sizeof (nvm_header); offset += LE32TOH (nvm_header.ImageLength); nvm_header.NextHeader = HTOLE32 (offset); } nvm_header.HeaderChecksum = 0; nvm_header.HeaderChecksum = checksum32 (&nvm_header, sizeof (nvm_header), 0); if (write (STDOUT_FILENO, &nvm_header, sizeof (nvm_header)) != sizeof (nvm_header)) { error (1, errno, NVM_HDR_CANTSAVE, file->name, image); } copyimage (file, LE32TOH (nvm_header.ImageLength), image); image++; return; }
/* Ramp colors to form a gradient between two specificed colors. For 8-bit images set up to ramp the palette, for 24-bit images ramp three lookup tables */ int rampcolors(COLORAMP *ramp, imgdes *srcimg, imgdes *resimg) { int rcode, buffsize=256, j; static UCHAR *redlut, *grnlut, *blulut; copyimage(srcimg, resimg); switch(srcimg->bmh->biBitCount){ case (8): resimg->palette[ramp->lo].rgbRed = ramp->lored; resimg->palette[ramp->lo].rgbGreen = ramp->logrn; resimg->palette[ramp->lo].rgbBlue = ramp->loblu; resimg->palette[ramp->hi].rgbRed = ramp->hired; resimg->palette[ramp->hi].rgbGreen = ramp->higrn; resimg->palette[ramp->hi].rgbBlue = ramp->hiblu; ramppalette(ramp->lo,ramp-> hi, resimg->palette); resimg->imgtype = 0; // Make sure it's not considered grayscale rcode = updatebitmapcolortable(resimg); break; case (24): redlut = (UCHAR far*)malloc(buffsize); grnlut = (UCHAR far*)malloc(buffsize); blulut = (UCHAR far*)malloc(buffsize); for(j=0; j<256; j++) { redlut[j] = grnlut[j] = blulut[j] = j; } redlut[ramp->lo] = ramp->lored; grnlut[ramp->lo] = ramp->logrn; blulut[ramp->lo] = ramp->loblu; redlut[ramp->hi] = ramp->hired; grnlut[ramp->hi] = ramp->higrn; blulut[ramp->hi] = ramp->hiblu; ramplut(ramp->lo, ramp->hi, redlut); ramplut(ramp->lo, ramp->hi, grnlut); ramplut(ramp->lo, ramp->hi, blulut); rcode = usetable(redlut, grnlut, blulut, resimg, resimg); free(blulut); free(grnlut); free(redlut); break; case (1): rcode = BAD_BPP; } return(rcode); }
Image<T> Geodilation(Image<T> &G, Image<T> &R, int connex, int niter) { Image<T> Geodilat(G.Dimx(), G.Dimy(), G.Dimz()); // Pink Images struct xvimage* imageG; struct xvimage* imageR; struct xvimage* temp; int32_t typepixel; if (sizeof(T)==1) typepixel = VFF_TYP_1_BYTE; else if (sizeof(T)==2) typepixel = VFF_TYP_2_BYTE; else if (sizeof(T)==4) typepixel = VFF_TYP_4_BYTE; else std::cerr<<"Error in Geodilation : ImageType not known"<<std::endl; imageG=allocheader(NULL,G.Dimx(),G.Dimy(),G.Dimz(),typepixel); imageG->image_data= G.GetPointer(); imageR=allocheader(NULL,G.Dimx(),G.Dimy(),G.Dimz(),typepixel); imageR->image_data= R.GetPointer(); temp=copyimage(imageG); lgeodilat(temp,imageR,connex,niter); for (int z = 0; z<G.Dimz() ; ++z){ for (int y = 0; y<G.Dimy() ; ++y){ for (int x = 0; x<G.Dimx(); ++x){ Geodilat(x, y, z) = ((T *)(temp->image_data))[x + y * G.Dimx() + z * G.Dimx() * G.Dimy()]; } } } free(imageR); free(imageG); free(temp); return Geodilat; }
/* =============================================================== */ int32_t l3dborder(struct xvimage * f) /* =============================================================== */ /* extrait la frontière interne def: closure{x in F | x free for F} */ { #undef F_NAME #define F_NAME "l3dborder" struct xvimage * g; index_t rs, cs, ds, ps; index_t x, y, z; uint8_t *F; uint8_t *G; assert(datatype(f) == VFF_TYP_1_BYTE); rs = rowsize(f); cs = colsize(f); ds = depth(f); ps = rs * cs; F = UCHARDATA(f); g = copyimage(f); if (g == NULL) { fprintf(stderr,"%s: copyimage failed\n", F_NAME); return 0; } G = UCHARDATA(g); razimage(f); for (z = 0; z < ds; z++) for (y = 0; y < cs; y++) for (x = 0; x < rs; x++) if (G[z*ps + y*rs + x] && FaceLibre3d(g, x, y, z)) F[z*ps + y*rs + x] = VAL_OBJET; l3dmakecomplex(f); freeimage(g); return 1; } /* l2dborder() */
static void function1 (struct _file_ * file, signed index, flag_t flags) { static signed image = 0; static uint32_t offset = 0; struct nvm_header1 nvm_header; if (read (file->file, &nvm_header, sizeof (nvm_header)) != sizeof (nvm_header)) { error (1, errno, NVM_HDR_CANTREAD, file->name, image); } if (LE32TOH (nvm_header.HEADERVERSION) != 0x60000000) { error (1, 0, NVM_HDR_VERSION, file->name, image); } if (checksum32 (&nvm_header, sizeof (nvm_header), 0)) { error (1, 0, NVM_HDR_CHECKSUM, file->name, image); } if (nvm_header.NEXTHEADER) { error (1, 0, NVM_HDR_LINK, file->name, image); } if (index) { offset += sizeof (nvm_header); offset += LE32TOH (nvm_header.IMAGELENGTH); nvm_header.NEXTHEADER = HTOLE32 (offset); } nvm_header.HEADERCHECKSUM = 0; nvm_header.HEADERCHECKSUM = checksum32 (&nvm_header, sizeof (nvm_header), 0); if (write (STDOUT_FILENO, &nvm_header, sizeof (nvm_header)) != sizeof (nvm_header)) { error (1, errno, NVM_HDR_CANTSAVE, file->name, image); } copyimage (file, LE32TOH (nvm_header.IMAGELENGTH), image); return; }
//-------------------------------------// void clTextureAtlas::AddTextureToAtlas(tyTextureAtlasPos *outTexturePos, unsigned int * data, int width, int height, int repeatWidth) { if (m_img_buffer == NULL) return; int widthSum = width + repeatWidth; if (outTexturePos != NULL) { outTexturePos->x = 0; outTexturePos->y = 0; outTexturePos->width = 0; outTexturePos->height = 0; } enumTexturSizeSlot slot = getSlotByHeight(height); if (slot == enumTexturSizeSlot::_TEXTURE_HEIGHT_COUNT) { m_error.AddError("Texture can't by coppyed to Texture Atlas! Texture height is out of range."); return; } if (widthSum > m_width) { m_error.AddError("Texture can't by coppyed to Texture Atlas! Texture width is to large!"); return; } if ((m_slot_pos_x[slot] + widthSum) > m_width) { if ((m_filled_y_pos + SLOT_HEIGHT[slot]) > m_height) { m_error.AddError("Texture can't by coppyed to Texture Atlas! Texture Atlas is FULL!"); return; } //- slot is full - create new! m_slot_pos_y[slot] = m_filled_y_pos; m_slot_pos_x[slot] = 0; m_filled_y_pos += SLOT_HEIGHT[slot]; } //- copy image to slot position int outX = m_slot_pos_x[slot]; int outY = m_slot_pos_y[slot]; copyimage(m_img_buffer, data, outX, outY, width, height, m_width); //- repeat a part of the image at the end of the original image if (repeatWidth > 0) { copyimage(m_img_buffer, data, outX + width, outY, repeatWidth, height, m_width, width); } //- move slot position m_slot_pos_x[slot] += widthSum; if (outTexturePos != NULL) { outTexturePos->x = outX; outTexturePos->y = outY; outTexturePos->width = widthSum; outTexturePos->height = height; } //- update fill state m_fillState += widthSum * height; }
int32_t main(int argc, char *argv[]) { struct xvimage *image, *edges; FILE *output, *amira_script; char output_format; double r, v, b; iv_scene* scene; list *ss_result, *ss_result2; complexe *temp, *intersect_edges, *point; uint32_t i, rs, ps, d, N, lim, erode, j, keep, k, max, num_pt, *tab_pt, kept; char name[BASE_ALLOC]; //******************************************* //Checking input values //******************************************* if (argc!=4) { fprintf(stderr, "usage: %s %s\n", argv[0], USAGE); return(-1); } //We read input image image=readimage(argv[1]); if (image==NULL) { fprintf(stderr, "Error: Could not read %s.\n", argv[1]); return(-1); } else if(datatype(image)!=VFF_TYP_1_BYTE) { fprintf(stderr, "Error: only CC image supported\n"); return(-1); } //We extract some info rs=rowsize(image1); cs=colsize(image1); d=depth(image1); N=rs*cs*d; //We produce the edges image edges=copyimage(image); if(edges==NULL) { fprintf(stderr, "Memory allocation error : not enough memory.\n"); return(-1); } //And keep only intersection edges in this image pix=0; for(k=0; k<d; k++) for(j=0; j<cs; j++) for(i=0; i<rs; i++) { if( (UCHARDATA(image1)[pix] & CC_AX) != 0) { t=cca_cardinal_containers(image1, pix, i, j, k, CC_AX, rs, rs*cs); if(t<3) UCHARDATA(image1)[pix]&=(255-CC_AX); } if( (UCHARDATA(image1)[pix] & CC_AY) != 0) { t=cca_cardinal_containers(image1, pix, i, j, k, CC_AY, rs, rs*cs); if(t<3) UCHARDATA(image1)[pix]&=(255-CC_AY); } if( (UCHARDATA(image1)[pix] & CC_AZ) != 0) { t=cca_cardinal_containers(image1, pix, i, j, k, CC_AZ, rs, rs*cs); if(t<3) UCHARDATA(image1)[pix]&=(255-CC_AZ); } pix++; } for(i=0; i<N; i++) UCHARDATA(image1)[i]&=255-(CC_VOL | CC_FXY | CC_FYZ | CC_FXZ | CC_PT); cca_makecomplex(image1); if(strcmp(argv[6], "keep")==0) { strategy=KEEP; } else if(strcmp(argv[6], "reject")==0) { strategy=REJECT; } else { fprintf(stderr, "usage: %s %s\n", argv[0], USAGE); return(-1); } mode_amira=0; if(argc==9) { if(strcmp(argv[8], "-amira")!=0) { fprintf(stderr, "usage: %s %s\n", argv[0], USAGE); freeimage(image); freeimage(edges); return(-1); } else { mode_amira=1; } } if(strcmp(argv[4], "fusion")==0) { mode=FUSION; } else if(strcmp(argv[4], "split")==0) { mode=SPLIT; } else { fprintf(stderr, "usage: %s %s\n", argv[0], USAGE); freeimage(image); freeimage(edges); return(-1); } rs=rowsize(image); ps=colsize(image)*rs; if(mode==SPLIT) { //Each surface will be written in different Inventor File //Create an AVIZO script which will allow to open all of them sprintf(name, "%s_avizo_load_script.hx", argv[3]); amira_script=fopen(name, "wb"); if(amira_script==NULL) { fprintf(stderr, "Error: could not create file %s. Check directory permission.\n", name); freeimage(image); freeimage(edges); return(-1); } amira_script_init(amira_script); } else { sprintf(name, "%s.iv", argv[3]); output = fopen(name, "wb"); if(output==NULL) { fprintf(stderr, "Error: could not create output file %s (directory exists?).\n", name); freeimage(image); freeimage(edges); return(-1); } } if(strcmp(argv[7], "NULL")!=0) { cca_image=allocimage(NULL, rs, ps/rs, depth(image), VFF_TYP_1_BYTE); if(cca_image==NULL) { fprintf(stderr, "Error: could not allocate memory\n"); freeimage(image); freeimage(edges); return(-1); } } else { cca_image=NULL; } //******************************************************* //Preparation of the image and the scene //******************************************************* //In case we don't have a complex, uncomment following //cca_makecomplex(image); scene=inventor_new_scene(10, NULL); //Initialize the scene... if(scene==NULL) { fprintf(stderr, "Error when creating new scene.\n"); return(-1); } //We add to our object the main materials (keep the surfaces for later) inventor_add_material_to_scene(scene, "MatPoint", POS_PT, 0.0, 0.0, 0.0, 0.1, 0.4, 0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); inventor_add_material_to_scene(scene, "MatAX", POS_AX, 0.0, 0.0, 0.0, 0.1, 0.1, 0.4, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); inventor_add_material_to_scene(scene, "MatAY", POS_AY, 0.0, 0.0, 0.0, 0.1, 0.1, 0.4, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); inventor_add_material_to_scene(scene, "MatAZ", POS_AZ, 0.0, 0.0, 0.0, 0.1, 0.1, 0.4, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); inventor_add_material_to_scene(scene, "MatVXY", POS_VXY, 0.0, 0.0, 0.0, 0.65, 0.65, 0.65, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); inventor_add_material_to_scene(scene, "MatVXZ", POS_VXZ, 0.0, 0.0, 0.0, 0.50, 0.50, 0.50, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); inventor_add_material_to_scene(scene, "MatVYZ", POS_VYZ, 0.0, 0.0, 0.0, 0.80, 0.80, 0.80, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); if(mode==FUSION) { scene->output=output; inventor_init_file(scene); } //******************************************************** //Make surface segmentation //******************************************************** //Get the intersection edges intersect_edges=cca_to_complexe(edges); freeimage(edges); if(intersect_edges==NULL) { fprintf(stderr, "Error in function cca_to_complexe()\n"); inventor_delete_scene(scene); freeimage(image); return (-1); } //Make separation of the complex into surface components ss_result=cca_simple_surface_segmentation_with_intersection_edges_and_exclusion_inclusion_image(image, intersect_edges, filter, strategy); if(ss_result==NULL) { fprintf(stderr, "Error: cca_simple_surface_segmentation_with_intersection_edges_and_exclusion_inclusion_image() failed.\n"); inventor_delete_scene(scene); freeimage(image); return(-1); } //We don't need the image anymore freeimage(image); fprintf(stdout, "Found %d surfaces\n", ss_result->cpt -2); //The first item is the set of all vertices... temp=(complexe*)list_pop(ss_result); if(mode==SPLIT) { //We don't care. complexe_free_complexe(temp); point=NULL; tab_pt=NULL; num_pt=0; } else if(mode==FUSION) { for(i=0; i<ss_result->cpt; i++) { //Choose a random color for surfaces r=((double)rand())/((double)RAND_MAX); v=((double)rand())/((double)RAND_MAX); b=((double)rand())/((double)RAND_MAX); sprintf(name, "SurfXY_%d", i); inventor_add_material_to_scene(scene, name, POS_FXY, r, v, b, r, v, b, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); r+=0.05; v+=0.05; b+=0.05; if(r>1.0) r=1.0; if(b>1.0) b=1.0; if(v>1.0) v=1.0; sprintf(name, "SurfXZ_%d", i); inventor_add_material_to_scene(scene, name, POS_FXZ, r, v, b, r, v, b, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); r+=0.05; v+=0.05; b+=0.05; if(r>1.0) r=1.0; if(b>1.0) b=1.0; if(v>1.0) v=1.0; sprintf(name, "SurfYZ_%d", i); inventor_add_material_to_scene(scene, name, POS_FYZ, r, v, b, r, v, b, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); inventor_write_material_to_file(scene, POS_FXY); inventor_write_material_to_file(scene, POS_FXZ); inventor_write_material_to_file(scene, POS_FYZ); } //All the surfaces will go in the same file. //The array of points therefore interest us, we keep it and write it in the inventor file point=temp; tab_pt=point->tab_pt_obj; num_pt=point->num_pt_obj; inventor_new_object(scene); //inventor_set_drawstyle(scene, INVISIBLE, 1, 1); inventor_declare_points(scene, "Points", tab_pt, num_pt, rs, ps, mode_amira); } //The second item is the set of all intersect edges... We don't care. temp=(complexe*)list_pop(ss_result); complexe_free_complexe(temp); //******************************************************* //Send the surfaces to output file //******************************************************* i=0; //Will be used for the filename kept=0; while(!list_isempty(ss_result)) { //Get the object to write temp=(complexe*)list_pop(ss_result); keep=1; if(keep==1) { if(cca_image!=NULL) complexe_add_to_cca(cca_image, temp); /* if(temp->num_fxy>0) {k=temp->tab_fxy[0]; f=CC_FXY;} else if(temp->num_fxz>0) {k=temp->tab_fxz[0]; f=CC_FXZ;} else if(temp->num_fyz>0) {k=temp->tab_fyz[0]; f=CC_FYZ;} else assert(0); l=cca_list_container(cca_image, k, getxfrompixnum(k, rs, ps), getyfrompixnum(k, rs, ps), getzfrompixnum(k, rs, ps), f, rs, ps); assert(l->cpt==2); while(!list_isempty(l)) { g=(face_desc*)list_pop(l); surf[kept][l->cpt -1]=LONGDATA(labels)[g->pixnumber]; free(g); } assert(surf[kept][0] != surf[kept][1]); if(surf[kept][0] > surf[kept][1]) { k=surf[kept][1]; surf[kept][1]=surf[kept][0]; surf[kept][0]=k; } */ kept++; if(mode==SPLIT) complexe_compute_vertex_array(temp, rs, ps); if(mode==SPLIT) { //Choose a random color for surfaces r=((double)rand())/((double)RAND_MAX); v=((double)rand())/((double)RAND_MAX); b=((double)rand())/((double)RAND_MAX); sprintf(name, "SurfXY_%d", i); inventor_add_material_to_scene(scene, name, POS_FXY, r, v, b, r, v, b, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); r+=0.05; v+=0.05; b+=0.05; if(r>1.0) r=1.0; if(b>1.0) b=1.0; if(v>1.0) v=1.0; sprintf(name, "SurfXZ_%d", i); inventor_add_material_to_scene(scene, name, POS_FXZ, r, v, b, r, v, b, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); r+=0.05; v+=0.05; b+=0.05; if(r>1.0) r=1.0; if(b>1.0) b=1.0; if(v>1.0) v=1.0; sprintf(name, "SurfYZ_%d", i); inventor_add_material_to_scene(scene, name, POS_FYZ, r, v, b, r, v, b, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); //Create an output file for the surface sprintf(name, "%s.surf%d.%d.iv", argv[3], temp->num_fxy+temp->num_fyz+temp->num_fxz, i); output = fopen(name, "wb"); if(output==NULL) { fprintf(stderr, "Error: could not create output file %s (directory exists?).\n", name); while(!list_isempty(ss_result)) { temp=(complexe*)list_pop(ss_result); complexe_free_complexe(temp); } list_delete(ss_result, NO_FREE_DATA); inventor_delete_scene(scene); return(-1); } //Link the output with the scene scene->output=output; //And initialise the scene and the points inventor_init_file(scene); inventor_new_object(scene); //inventor_set_drawstyle(scene, INVISIBLE, 1, 1); inventor_declare_points(scene, "Points", temp->tab_pt_obj, temp->num_pt_obj, rs, ps, mode_amira); tab_pt=temp->tab_pt_obj; num_pt=temp->num_pt_obj; temp->num_pt_obj=0; temp->tab_pt_obj=NULL; } inventor_new_object(scene); if(mode==FUSION) { sprintf(name, "SurfXY_%d", i); inventor_add_material_to_scene(scene, name, POS_FXY, r, v, b, r, v, b, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); sprintf(name, "SurfXZ_%d", i); inventor_add_material_to_scene(scene, name, POS_FXZ, r, v, b, r, v, b, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); sprintf(name, "SurfYZ_%d", i); inventor_add_material_to_scene(scene, name, POS_FYZ, r, v, b, r, v, b, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); } //inventor_call_defined(scene, "Points"); complexe_to_inventor(scene, temp, num_pt, tab_pt, rs, ps, mode_amira); inventor_close_object(scene); fflush(scene->output); if(mode==SPLIT) { inventor_close_object(scene); fclose(scene->output); //For the amira script k=0; max=0; while(name[k]!='\0') { if(name[k]=='/') max=k+1; k++; } amira_script_add_iv_file(amira_script, &name[max], 1, 30*(i+1)); free(tab_pt); } } i++; complexe_free_complexe(temp); } if(mode==FUSION) { inventor_close_object(scene); fclose(scene->output); } fprintf(stdout, "Kept %d surfaces\n", kept); /*for(i=0; i<kept-1; i++) for(k=i+1; k<kept; k++) { if( */ if(cca_image!=NULL) { writeimage(cca_image, argv[7]); freeimage(cca_image); } //**************************************************** //Program ends //**************************************************** inventor_delete_scene(scene); list_delete(ss_result, NO_FREE_DATA); if(filter!=NULL) freeimage(filter); if(mode==SPLIT) fclose(amira_script); return(0); }
/***************************************************************************** * Render: displays previously rendered output ***************************************************************************** * This function send the currently rendered image to Distort image, waits * until it is displayed and switch the two rendering buffers, preparing next * frame. *****************************************************************************/ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) { picture_t *p_outpic; unsigned int w, h; int x,y; uint8_t u,v; picture_t *p_converted; video_format_t fmt_out; memset( &fmt_out, 0, sizeof(video_format_t) ); fmt_out.p_palette = NULL; if( !p_pic ) return NULL; p_outpic = filter_NewPicture( p_filter ); if( !p_outpic ) { picture_Release( p_pic ); return NULL; } if( !p_filter->p_sys->p_image ) p_filter->p_sys->p_image = image_HandlerCreate( p_filter ); /* chrominance */ u = p_filter->p_sys->u; v = p_filter->p_sys->v; for( y = 0; y<p_outpic->p[U_PLANE].i_lines; y++) { vlc_memset( p_outpic->p[U_PLANE].p_pixels+y*p_outpic->p[U_PLANE].i_pitch, u, p_outpic->p[U_PLANE].i_pitch ); vlc_memset( p_outpic->p[V_PLANE].p_pixels+y*p_outpic->p[V_PLANE].i_pitch, v, p_outpic->p[V_PLANE].i_pitch ); if( v == 0 && u != 0 ) u --; else if( u == 0xff ) v --; else if( v == 0xff ) u ++; else if( u == 0 ) v ++; } /* luminance */ vlc_memcpy( p_outpic->p[Y_PLANE].p_pixels, p_pic->p[Y_PLANE].p_pixels, p_outpic->p[Y_PLANE].i_lines * p_outpic->p[Y_PLANE].i_pitch ); /* image visualization */ fmt_out = p_filter->fmt_out.video; fmt_out.i_width = p_filter->fmt_out.video.i_width*p_filter->p_sys->scale/150; fmt_out.i_height = p_filter->fmt_out.video.i_height*p_filter->p_sys->scale/150; p_converted = image_Convert( p_filter->p_sys->p_image, p_pic, &(p_pic->format), &fmt_out ); if( p_converted ) { #define copyimage( plane, b ) \ for( y=0; y<p_converted->p[plane].i_visible_lines; y++) { \ for( x=0; x<p_converted->p[plane].i_visible_pitch; x++) { \ int nx, ny; \ if( p_filter->p_sys->yinc == 1 ) \ ny= y; \ else \ ny = p_converted->p[plane].i_visible_lines-y; \ if( p_filter->p_sys->xinc == 1 ) \ nx = x; \ else \ nx = p_converted->p[plane].i_visible_pitch-x; \ p_outpic->p[plane].p_pixels[(p_filter->p_sys->x*b+nx)+(ny+p_filter->p_sys->y*b)*p_outpic->p[plane].i_pitch ] = p_converted->p[plane].p_pixels[y*p_converted->p[plane].i_pitch+x]; \ } } copyimage( Y_PLANE, 2 ); copyimage( U_PLANE, 1 ); copyimage( V_PLANE, 1 ); #undef copyimage picture_Release( p_converted ); } else { msg_Err( p_filter, "Image scaling failed miserably." ); } p_filter->p_sys->x += p_filter->p_sys->xinc; p_filter->p_sys->y += p_filter->p_sys->yinc; p_filter->p_sys->scale += p_filter->p_sys->scaleinc; if( p_filter->p_sys->scale >= 50 ) p_filter->p_sys->scaleinc = -1; if( p_filter->p_sys->scale <= 1 ) p_filter->p_sys->scaleinc = 1; w = p_filter->fmt_out.video.i_width*p_filter->p_sys->scale/150; h = p_filter->fmt_out.video.i_height*p_filter->p_sys->scale/150; if( p_filter->p_sys->x*2 + w >= p_filter->fmt_out.video.i_width ) p_filter->p_sys->xinc = -1; if( p_filter->p_sys->x <= 0 ) p_filter->p_sys->xinc = 1; if( p_filter->p_sys->x*2 + w >= p_filter->fmt_out.video.i_width ) p_filter->p_sys->x = (p_filter->fmt_out.video.i_width-w)/2; if( p_filter->p_sys->y*2 + h >= p_filter->fmt_out.video.i_height ) p_filter->p_sys->y = (p_filter->fmt_out.video.i_height-h)/2; if( p_filter->p_sys->y*2 + h >= p_filter->fmt_out.video.i_height ) p_filter->p_sys->yinc = -1; if( p_filter->p_sys->y <= 0 ) p_filter->p_sys->yinc = 1; for( y = 0; y< 16; y++ ) { if( p_filter->p_sys->v == 0 && p_filter->p_sys->u != 0 ) p_filter->p_sys->u -= 1; else if( p_filter->p_sys->u == 0xff ) p_filter->p_sys->v -= 1; else if( p_filter->p_sys->v == 0xff ) p_filter->p_sys->u += 1; else if( p_filter->p_sys->u == 0 ) p_filter->p_sys->v += 1; } return CopyInfoAndRelease( p_outpic, p_pic ); }
/* ==================================== */ int32_t lsquelval3d(struct xvimage *image, // entree/sortie: image originale / squelette struct xvimage *dx, // entree/sortie: distance / distance topologique int32_t connex, int32_t val_inhibit) /* ==================================== */ { int32_t i, j, k; int32_t x; /* index muet de pixel */ int32_t y; /* index muet (generalement un voisin de x) */ int32_t rs = rowsize(image); /* taille ligne */ int32_t cs = colsize(image); /* taille colonne */ int32_t ps = rs * cs; /* taille plan */ int32_t ds = depth(image); int32_t N = ds * ps; /* taille image */ struct xvimage *dt; /* pour le calcul de la "distance topologique" */ uint8_t *IM = UCHARDATA(image); /* l'image de depart */ uint32_t *DX; /* fonction distance au complementaire de IM */ uint32_t *DT; /* fonction "distance topologique" */ uint32_t d; Rbt * RBT; int32_t taillemaxrbt; int32_t mctopo3d_t6mm, mctopo3d_t26mm, t6p, mctopo3d_t26p; IndicsInit(N); mctopo3d_init_topo3d(); if ((rowsize(dx) != rs) || (colsize(dx) != cs) || (depth(dx) != ds)) { fprintf(stderr, "%s() : bad size for dx\n", F_NAME); return(0); } if (datatype(dx) != VFF_TYP_4_BYTE) { fprintf(stderr, "%s() : datatype(dx) must be uint32_t\n", F_NAME); return(0); } DX = ULONGDATA(dx); dt = copyimage(dx); DT = ULONGDATA(dt); taillemaxrbt = 2 * rs * cs + 2 * rs * ds + 2 * ds * cs; /* cette taille est indicative, le RBT est realloue en cas de depassement */ RBT = mcrbt_CreeRbtVide(taillemaxrbt); if (RBT == NULL) { fprintf(stderr, "%s() : mcrbt_CreeRbtVide failed\n", F_NAME); return(0); } /* ================================================ */ /* PREMIERE PHASE */ /* ================================================ */ #ifdef VERBOSE printf("1ere etape\n"); #endif // INITIALISATION DT for (x = 0; x < N; x++) if (IM[x]) DT[x] = -1; else DT[x] = 0; // INITIALISATION DU RBT for (x = 0; x < N; x++) if (IM[x] && (DX[x] != val_inhibit) && mctopo3d_bordext26(IM, x, rs, ps, N)) { mcrbt_RbtInsert(&RBT, DX[x], x); Set(x, EN_RBT); } // if, for d = 1; if (connex == 6) { while (!mcrbt_RbtVide(RBT)) { x = RbtPopMin(RBT); UnSet(x, EN_RBT); if (mctopo3d_simple6(IM, x, rs, ps, N)) { DT[x] = d; IM[x] = 0; d++; for (k = 0; k < 26; k += 1) /* parcourt les voisins en 26-connexite */ { /* pour empiler les voisins */ y = voisin26(x, k, rs, ps, N); /* non deja empiles */ if ((y != -1) && (IM[y]) && (DX[y] != val_inhibit) && (! IsSet(y, EN_RBT))) { mcrbt_RbtInsert(&RBT, DX[y], y); Set(y, EN_RBT); } /* if y */ } /* for k */ } // if (mctopo3d_simple6(IM, x, rs, N)) } /* while (!mcrbt_RbtVide(RBT)) */ } /* if (connex == 6) */ else if (connex == 26) { while (!mcrbt_RbtVide(RBT)) { x = RbtPopMin(RBT); UnSet(x, EN_RBT); if (mctopo3d_simple26(IM, x, rs, ps, N)) { DT[x] = d; IM[x] = 0; d++; for (k = 0; k < 26; k += 1) /* parcourt les voisins en 26-connexite */ { /* pour empiler les voisins */ y = voisin26(x, k, rs, ps, N); /* non deja empiles */ if ((y != -1) && (IM[y]) && (DX[y] != val_inhibit) && (! IsSet(y, EN_RBT))) { mcrbt_RbtInsert(&RBT, DX[y], y); Set(y, EN_RBT); } /* if y */ } /* for k */ } // if (mctopo3d_simple26(IM, x, rs, N)) } /* while (!mcrbt_RbtVide(RBT)) */ } /* if (connex == 26) */ /* ================================================ */ /* SECONDE PHASE */ /* ================================================ */ #ifdef VERBOSE printf("2eme etape\n"); #endif // INITIALISATION DU RBT for (k = 1; k < ds-1; k++) for (j = 1; j < cs-1; j++) for (i = 1; i < rs-1; i++) { x = k * ps + j * rs + i; if (DT[x]) mcrbt_RbtInsert(&RBT, DT[x], x); } if (connex == 6) { int32_t abaisse; while (!mcrbt_RbtVide(RBT)) { x = RbtPopMin(RBT); do { abaisse = 0; mctopo3d_nbtopoh3d26_l((int32_t *)DT, x, DT[x], rs, ps, N, &t6p, &mctopo3d_t26mm); if ((t6p == 1) && (mctopo3d_t26mm == 1)) { mctopo3d_nbtopoh3d26_l((int32_t *)DT, x, DT[x], rs, ps, N, &t6p, &mctopo3d_t26mm); if ((t6p == 1) && (mctopo3d_t26mm == 1)) { d = mctopo3d_alpha26m_l((int32_t *)DT, x, rs, ps, N); d = mcmin((DT[x]-1),(d+1)); DT[x] = d; abaisse = 1; } } } while (abaisse); } /* while (!mcrbt_RbtVide(RBT)) */ } /* if (connex == 6) */ else if (connex == 26) { int32_t abaisse; while (!mcrbt_RbtVide(RBT)) { x = RbtPopMin(RBT); do { abaisse = 0; mctopo3d_nbtopoh3d6_l((int32_t *)DT, x, DT[x], rs, ps, N, &mctopo3d_t26p, &mctopo3d_t6mm); if ((mctopo3d_t26p == 1) && (mctopo3d_t6mm == 1)) { mctopo3d_nbtopoh3d26_l((int32_t *)DT, x, DT[x], rs, ps, N, &mctopo3d_t26p, &mctopo3d_t6mm); if ((mctopo3d_t26p == 1) && (mctopo3d_t6mm == 1)) { d = mctopo3d_alpha26m_l((int32_t *)DT, x, rs, ps, N); d = mcmin((DT[x]-1),(d+1)); DT[x] = d; abaisse = 1; } } } while (abaisse); } /* while (!mcrbt_RbtVide(RBT)) */ } /* if (connex == 26) */ // RECUPERATION DU RESULTAT d = 0; for (x = 0; x < N; x++) if ((DT[x] > d) && (DT[x] < INFINI)) d = DT[x]; d += 1; for (x = 0; x < N; x++) if (DT[x] == INFINI) DX[x] = d; else DX[x] = DT[x]; /* ================================================ */ /* UN PEU DE MENAGE */ /* ================================================ */ mctopo3d_termine_topo3d(); IndicsTermine(); mcrbt_RbtTermine(RBT); freeimage(dt); return(1); } /* lsquelval3d() */
/* ==================================== */ int32_t lsquelsmoothval(struct xvimage *image, // entree/sortie: image originale / squelette struct xvimage *dx, // entree/sortie: distance / distance topologique struct xvimage *ni, // entree/sortie: niveaux - image 1D struct xvimage *gr, // entree: gradient int32_t connex, int32_t val_inhibit, int32_t rayon) /* ==================================== */ #undef F_NAME #define F_NAME "lsquelsmoothval" { int32_t k; int32_t x; /* index muet de pixel */ int32_t y; /* index muet (generalement un voisin de x) */ int32_t rs = rowsize(image); /* taille ligne */ int32_t cs = colsize(image); /* taille colonne */ int32_t N = rs * cs; /* taille image */ struct xvimage *dt; /* pour le calcul de la "distance topologique" */ uint32_t *DT; /* fonction "distance topologique" */ uint8_t *IM = UCHARDATA(image); /* l'image de depart */ uint32_t *DX = ULONGDATA(dx); /* fonction distance au complementaire de IM */ uint8_t *NI = UCHARDATA(ni); /* fonction niveau (1D) - taille N * 1 */ uint8_t *GR = UCHARDATA(gr); /* fonction gradient */ uint32_t d; Rbt * RBT; int32_t taillemaxrbt; Liste * cx; // pour le cercle de centre x Liste * cy; // pour le cercle de centre y uint32_t dmax; IndicsInit(N); if ((rowsize(dx) != rs) || (colsize(dx) != cs) || (depth(dx) != 1)) { fprintf(stderr, "%s() : bad size for dx\n", F_NAME); return(0); } if (datatype(dx) != VFF_TYP_4_BYTE) { fprintf(stderr, "%s() : datatype(dx) must be uint32_t\n", F_NAME); return(0); } if ((rowsize(ni) != N) || (colsize(ni) != 1) || (depth(ni) != 1)) { fprintf(stderr, "%s() : bad size for ni\n", F_NAME); return(0); } dt = copyimage(dx); DT = ULONGDATA(dt); taillemaxrbt = 2 * rs + 2 * cs ; /* cette taille est indicative, le RBT est realloue en cas de depassement */ RBT = mcrbt_CreeRbtVide(taillemaxrbt); if (RBT == NULL) { fprintf(stderr, "%s() : mcrbt_CreeRbtVide failed\n", F_NAME); return(0); } for (dmax = 0, x = 0; x < N; x++) if (DX[x] > dmax) dmax = DX[x]; // INITIALISATION DT for (x = 0; x < N; x++) if (IM[x]) DT[x] = INFINI; else DT[x] = 0; // INITIALISATION DU RBT for (x = 0; x < N; x++) if (IM[x] && (DX[x] != val_inhibit) && bordext8(IM, x, rs, N)) { mcrbt_RbtInsert(&RBT, DX[x], x); Set(x, EN_RBT); } // if, for cx = CreeListeVide(2*rs + 2*cs); cy = CreeListeVide(2*rs + 2*cs); d = 1; if (connex == 4) { while (!mcrbt_RbtVide(RBT)) { x = RbtPopMin(RBT); UnSet(x, EN_RBT); #ifdef DEBUG printf("pop x = %d,%d, im = %d, dx = %ld\n", x%rs, x/rs, IM[x], DX[x]); #endif if (simple4(IM, x, rs, N)) { if (smooth(image, x, rayon, cx, cy)) { NI[d] = GR[x]; DT[x] = d; IM[x] = 0; d++; for (k = 0; k < 8; k += 1) /* parcourt les voisins en 8-connexite */ { /* pour empiler les voisins */ y = voisin(x, k, rs, N); /* non deja empiles */ if ((y != -1) && (IM[y]) && (DX[y] != val_inhibit) && (! IsSet(y, EN_RBT))) { mcrbt_RbtInsert(&RBT, DX[y], y); Set(y, EN_RBT); } /* if y */ } /* for k */ } else { DX[x] += INCR_PRIO; if (DX[x] > dmax) break; mcrbt_RbtInsert(&RBT, DX[x], x); Set(x, EN_RBT); } } // if (simple4(IM, x, rs, N)) } /* while (!mcrbt_RbtVide(RBT)) */ } /* if (connex == 4) */ else if (connex == 8) { printf("connex 8 NYI\n"); } /* if (connex == 8) */ // RECUPERATION DU RESULTAT d = 0; // valeur pour l'infini: plus grande valeur finie + 1 for (x = 0; x < N; x++) if ((DT[x] > d) && (DT[x] < INFINI)) d = DT[x]; d += 1; for (x = 0; x < N; x++) if (DT[x] == INFINI) DX[x] = d; else DX[x] = DT[x]; /* ================================================ */ /* UN PEU DE MENAGE */ /* ================================================ */ IndicsTermine(); mcrbt_RbtTermine(RBT); freeimage(dt); ListeTermine(cx); ListeTermine(cy); return(1); } /* lsquelsmoothval() */
/* =============================================================== */ int32_t latf_old(struct xvimage * image, int32_t connexmin, int32_t rayonmin, int32_t rayonmax) /* =============================================================== */ #undef F_NAME #define F_NAME "latf" { struct xvimage * copy; int32_t rayon; int32_t rs, cs, ds, ps, N; int32_t ndes; rs = rowsize(image); /* taille ligne */ cs = colsize(image); /* taille colonne */ ps = rs * cs; /* taille plan */ ds = depth(image); /* nombre plans */ N = ds * ps; /* taille image */ if (ds == 1) /* ======================= 2D ========================*/ { if (rayonmin == 0) { p_despics(image, connexmin); p_despuits(image, connexmin); rayonmin++; } copy = copyimage(image); if (copy == NULL) { fprintf(stderr, "%s: copyimage failed\n", F_NAME); return 0; } for (rayon = rayonmin; rayon <= rayonmax; rayon++) { #ifdef VERBOSE fprintf(stderr, "%s: rayon = %d\n", F_NAME, rayon); #endif do { if (! lhthindelta(image, NULL, rayon, connexmin)) { fprintf(stderr, "%s: lhthindelta failed\n", F_NAME); return 0; } ndes = p_despics(image, connexmin); if (! lhtkernu(image, copy, connexmin)) { fprintf(stderr, "%s: lhtkernu failed\n", F_NAME); return 0; } } while (ndes); memcpy(UCHARDATA(copy), UCHARDATA(image), N); do { if (! lhthickdelta(image, NULL, rayon, connexmin)) { fprintf(stderr, "%s: lhthickdelta failed\n", F_NAME); return 0; } ndes = p_despuits(image, connexmin); if (! lhtkern(image, copy, connexmin)) { fprintf(stderr, "%s: lhtkern failed\n", F_NAME); return 0; } } while (ndes); if (rayon < rayonmax) memcpy(UCHARDATA(copy), UCHARDATA(image), N); } /* for (rayon = 1; rayon <= rayonmax; rayon++) */ } else /* ============================== 3D ================================*/ { fprintf(stderr, "%s: 3D Not Yet Implemented\n", F_NAME); return 0; } freeimage(copy); return 1; } /* latf_old() */
/* ==================================== */ int32_t lsquelval(struct xvimage *image, // entree/sortie: image originale / squelette struct xvimage *dx, // entree/sortie: distance / distance topologique int32_t connex, int32_t val_inhibit) /* ==================================== */ #undef F_NAME #define F_NAME "lsquelval" { int32_t k; int32_t x; /* index muet de pixel */ int32_t y; /* index muet (generalement un voisin de x) */ int32_t rs = rowsize(image); /* taille ligne */ int32_t cs = colsize(image); /* taille colonne */ int32_t N = rs * cs; /* taille image */ struct xvimage *dt; /* pour le calcul de la "distance topologique" */ uint8_t *IM = UCHARDATA(image); /* l'image de depart */ uint32_t *DX; /* fonction distance au complementaire de IM */ uint32_t *DT; /* fonction "distance topologique" */ uint32_t d; Rbt * RBT; int32_t taillemaxrbt; IndicsInit(N); if ((rowsize(dx) != rs) || (colsize(dx) != cs) || (depth(dx) != 1)) { fprintf(stderr, "%s() : bad size for dx\n", F_NAME); return(0); } if (datatype(dx) != VFF_TYP_4_BYTE) { fprintf(stderr, "%s() : datatype(dx) must be uint32_t\n", F_NAME); return(0); } DX = ULONGDATA(dx); dt = copyimage(dx); DT = ULONGDATA(dt); taillemaxrbt = 2 * rs + 2 * cs ; /* cette taille est indicative, le RBT est realloue en cas de depassement */ RBT = mcrbt_CreeRbtVide(taillemaxrbt); if (RBT == NULL) { fprintf(stderr, "%s() : mcrbt_CreeRbtVide failed\n", F_NAME); return(0); } /* ================================================ */ /* PREMIERE PHASE */ /* ================================================ */ #ifdef VERBOSE printf("1ere etape\n"); #endif // INITIALISATION DT for (x = 0; x < N; x++) if (IM[x]) DT[x] = INFINI; else DT[x] = 0; // INITIALISATION DU RBT for (x = 0; x < N; x++) if (IM[x] && (DX[x] != val_inhibit) && bordext8(IM, x, rs, N)) { mcrbt_RbtInsert(&RBT, DX[x], x); Set(x, EN_RBT); } // if, for d = 1; if (connex == 4) { while (!mcrbt_RbtVide(RBT)) { x = RbtPopMin(RBT); UnSet(x, EN_RBT); #ifdef DEBUG printf("pop x = %d,%d, im = %d, dx = %ld\n", x%rs, x/rs, IM[x], DX[x]); #endif if (simple4(IM, x, rs, N)) { DT[x] = d; IM[x] = 0; d++; for (k = 0; k < 8; k += 1) /* parcourt les voisins en 8-connexite */ { /* pour empiler les voisins */ y = voisin(x, k, rs, N); /* non deja empiles */ if ((y != -1) && (IM[y]) && (DX[y] != val_inhibit) && (! IsSet(y, EN_RBT))) { mcrbt_RbtInsert(&RBT, DX[y], y); Set(y, EN_RBT); } /* if y */ } /* for k */ } // if (simple4(IM, x, rs, N)) } /* while (!mcrbt_RbtVide(RBT)) */ } /* if (connex == 4) */ else if (connex == 8) { while (!mcrbt_RbtVide(RBT)) { x = RbtPopMin(RBT); UnSet(x, EN_RBT); #ifdef DEBUG printf("pop x = %d,%d, im = %d, dx = %ld\n", x%rs, x/rs, IM[x], DX[x]); #endif if (simple8(IM, x, rs, N)) { DT[x] = d; IM[x] = 0; d++; for (k = 0; k < 8; k += 1) /* parcourt les voisins en 8-connexite */ { /* pour empiler les voisins */ y = voisin(x, k, rs, N); /* non deja empiles */ if ((y != -1) && (IM[y]) && (DX[y] != val_inhibit) && (! IsSet(y, EN_RBT))) { mcrbt_RbtInsert(&RBT, DX[y], y); Set(y, EN_RBT); } /* if y */ } /* for k */ } // if (simple8(IM, x, rs, N)) } /* while (!mcrbt_RbtVide(RBT)) */ } /* if (connex == 8) */ #ifdef DEBUG writeimage(dt, "_dt"); #endif /* ================================================ */ /* SECONDE PHASE */ /* ================================================ */ #ifdef SECONDE_PHASE stabilite = 0; while (!stabilite) { #ifdef VERBOSE printf("2eme etape\n"); #endif stabilite = 1; // INITIALISATION DU RBT for (j = 1; j < cs-1; j++) for (i = 1; i < rs-1; i++) { x = j * rs + i; if (DT[x] && (DT[x] != INFINI)) mcrbt_RbtInsert(&RBT, DT[x], x); } if (connex == 4) { while (!mcrbt_RbtVide(RBT)) { x = RbtPopMin(RBT); #ifdef DEBUG printf("pop x = %d,%d, dt = %ld\n", x%rs, x/rs, DT[x]); #endif if (abaisse4(x, DT, rs, N)) { stabilite = 0; #ifdef DEBUG printf("abaisse a %ld\n", DT[x]); #endif } // if (abaisse4(x, DT, rs, N)) } // while (!mcrbt_RbtVide(RBT)) } // if (connex == 4) else if (connex == 8) { int32_t abaisse; while (!mcrbt_RbtVide(RBT)) { x = RbtPopMin(RBT); #ifdef DEBUG printf("pop x = %d,%d, dt = %d\n", x%rs, x/rs, DT[x]); #endif if (abaisse8(x, DT, rs, N)) { stabilite = 0; #ifdef DEBUG printf("abaisse a %ld\n", DT[x]); #endif } // if (abaisse8(x, DT, rs, N)) } // while (!mcrbt_RbtVide(RBT)) } // if (connex == 8) } // while (!stabilite) #endif // RECUPERATION DU RESULTAT d = 0; // valeur pour l'infini: plus grande valeur finie + 1 for (x = 0; x < N; x++) if ((DT[x] > d) && (DT[x] < INFINI)) d = DT[x]; d += 1; for (x = 0; x < N; x++) if (DT[x] == INFINI) DX[x] = d; else DX[x] = DT[x]; /* ================================================ */ /* UN PEU DE MENAGE */ /* ================================================ */ IndicsTermine(); mcrbt_RbtTermine(RBT); freeimage(dt); return(1); } /* lsquelval() */
/* =============================================================== */ int32_t ltaflambda(struct xvimage * image, int32_t connexmin, int32_t rayon, int32_t lambdapics, int32_t lambdapuits) /* =============================================================== */ #undef F_NAME #define F_NAME "ltaflambda" { struct xvimage * copy; struct xvimage * save; int32_t rs, cs, ds, ps, N; int32_t ndes; rs = rowsize(image); /* taille ligne */ cs = colsize(image); /* taille colonne */ ps = rs * cs; /* taille plan */ ds = depth(image); /* nombre plans */ N = ds * ps; /* taille image */ if (rayon == -1) rayon = 2000000000; if (ds == 1) /* ======================= 2D ========================*/ { copy = copyimage(image); save = copyimage(image); if ((copy == NULL) || (save == NULL)) { fprintf(stderr, "%s: copyimage failed\n", F_NAME); return 0; } do { if (! lhthindelta(image, NULL, rayon, connexmin)) { fprintf(stderr, "%s: lhthindelta failed\n", F_NAME); return 0; } ndes = p_deslambdapics(image, connexmin, lambdapics); if (! lhtkernu(image, copy, connexmin)) { fprintf(stderr, "%s: lhtkernu failed\n", F_NAME); return 0; } subimage(copy, image); memcpy(UCHARDATA(image), UCHARDATA(save), N); if (! lhthickdelta(image, NULL, rayon, connexmin)) { fprintf(stderr, "%s: lhthickdelta failed\n", F_NAME); return 0; } ndes += p_deslambdapuits(image, connexmin, lambdapuits); if (! lhtkern(image, save, connexmin)) { fprintf(stderr, "%s: lhtkern failed\n", F_NAME); return 0; } subimage(image, copy); if (ndes) { memcpy(UCHARDATA(copy), UCHARDATA(image), N); memcpy(UCHARDATA(save), UCHARDATA(image), N); } } while (ndes); } else /* ============================== 3D ================================*/ { fprintf(stderr, "%s: 3D Not Yet Implemented\n", F_NAME); return 0; } freeimage(copy); freeimage(save); return 1; } /* ltaflambda() */
/* ==================================== */ int32_t lmaxdiameter(struct xvimage *image, int32_t connex) /* ==================================== */ { int32_t x; /* index muet de pixel */ int32_t rs = rowsize(image); /* taille ligne */ int32_t cs = colsize(image); /* taille colonne */ int32_t ds = depth(image); /* nb plans */ int32_t ps = rs * cs; /* taille plan */ int32_t N = ps * ds; /* taille image */ uint8_t *I = UCHARDATA(image); /* l'image de depart */ struct xvimage *tmp; uint8_t *T; //GUJUN int32_t x1, x1max; int32_t y1, y1max; int32_t z1, z1max; int32_t x2, x2max; int32_t y2, y2max; int32_t z2, z2max; double distance = -1; double temp = 0; int32_t i; switch(datatype(image)) { case VFF_TYP_1_BYTE: tmp = copyimage(image); if (tmp == NULL) { fprintf(stderr, "lmaxdiameter: copyimage failed\n"); return 0; } T = UCHARDATA(tmp); switch (connex) { case 4: for (x = 0; x < N; x++) if (T[x] && (nbvoisc8(T,x,rs,N)) == 0) I[x] = NDG_MIN; break; case 8: for (x = 0; x < N; x++) if (T[x] && (nbvoisc4(T,x,rs,N)) == 0) I[x] = NDG_MIN; break; case 6: for (x = 0; x < N; x++) if (T[x] && (mctopo3d_nbvoisc6(T,x,rs,ps,N)) == 0) I[x] = NDG_MIN; break; case 18: for (x = 0; x < N; x++) if (T[x] && (mctopo3d_nbvoisc18(T,x,rs,ps,N)) == 0) I[x] = NDG_MIN; break; case 26: for (x = 0; x < N; x++) if (T[x] && (mctopo3d_nbvoisc26(T,x,rs,ps,N)) == 0) I[x] = NDG_MIN; break; default: fprintf(stderr, "lmaxdiameter: mauvaise connexite: %d\n", connex); return 0; } /* switch (connex) */ //GUJun //Deux dimentions x et y if ((connex == 4)||(connex == 8)) { for( x = 0; x < N; x++) { // Le premier point au border if( I[x] != NDG_MIN ) { x1 = x%rs; y1 = x/rs; for (i = x+1; i < N; i++) { //Le deuxième point au border if( I[i] != NDG_MIN ) { x2 = i%rs; y2 = i/rs; temp = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)); //Le plus int32_t axe if (temp > distance) { distance = temp; x1max = x1; y1max = y1; x2max = x2; y2max = y2; } } } } } for( x = 0; x < N; x++) I[x] = NDG_MIN; I[x1max+y1max*rs] = NDG_MAX; I[x2max+y2max*rs] = NDG_MAX; } //Trois dimentions x,y et z else if ((connex == 6)||(connex == 18)||(connex == 26)) { for ( x = 0; x < N; x++) { if( I[x] != NDG_MIN ) { z1 = x/ps; x1 = (x%ps)%rs; y1 = (x%ps)/rs; for(i = x+1; i < N; i++) { if( I[i] != NDG_MIN ) { z2 = i/ps; x2 = (i%ps)%rs; y2 = (i%ps)/rs; temp = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2)); if (temp > distance) { distance = temp; x1max = x1; y1max = y1; z1max = z1; x2max = x2; y2max = y2; z2max = z2; } } } } } for( x = 0; x < N; x++) I[x] = NDG_MIN; I[x1max+y1max*rs+z1max*ps] = NDG_MAX; I[x2max+y2max*rs+z2max*ps] = NDG_MAX; } //GUJun break; default: fprintf(stderr,"lmaxdiameter() : bad data type %d\n", datatype(image)); return 0; } /* switch(datatype(image)) */ if (distance == -1) { fprintf(stderr,"lmaxdiameter() : not enough data\n"); return 0; } freeimage(tmp); return(1); }
/* Final processing of object data, just before saving it to the catalog. */ void endobject(picstruct *field, picstruct *dfield, picstruct *wfield, picstruct *dwfield, int n, objliststruct *objlist) { checkstruct *check; int i,j, ix,iy,selecflag, newnumber,nsub; objstruct *obj; obj = &objlist->obj[n]; /* Current FITS extension */ obj2->ext_number = thecat.currext; /* Source position */ obj2->sposx = (float)(obj2->posx = obj->mx+1.0); /* That's standard FITS */ obj2->sposy = (float)(obj2->posy = obj->my+1.0); /* Integer coordinates */ ix=(int)(obj->mx+0.49999); iy=(int)(obj->my+0.49999); /* Association */ if (prefs.assoc_flag) obj2->assoc_number = do_assoc(field, obj2->sposx, obj2->sposy); if (prefs.assoc_flag && prefs.assocselec_type!=ASSOCSELEC_ALL) selecflag = (prefs.assocselec_type==ASSOCSELEC_MATCHED)? obj2->assoc_number:!obj2->assoc_number; else selecflag = 1; if (selecflag) { /*-- Paste back to the image the object's pixels if BLANKing is on */ if (prefs.blank_flag) { pasteimage(field, obj->blank, obj->subw, obj->subh, obj->subx, obj->suby); if (obj->dblank) pasteimage(dfield, obj->dblank, obj->subw, obj->subh, obj->subx, obj->suby); } /*------------------------- Error ellipse parameters ------------------------*/ if (FLAG(obj2.poserr_a)) { double pmx2,pmy2,temp,theta; if (fabs(temp=obj->poserr_mx2-obj->poserr_my2) > 0.0) theta = atan2(2.0 * obj->poserr_mxy,temp) / 2.0; else theta = PI/4.0; temp = sqrt(0.25*temp*temp+obj->poserr_mxy*obj->poserr_mxy); pmy2 = pmx2 = 0.5*(obj->poserr_mx2+obj->poserr_my2); pmx2+=temp; pmy2-=temp; obj2->poserr_a = (float)sqrt(pmx2); obj2->poserr_b = (float)sqrt(pmy2); obj2->poserr_theta = theta*180.0/PI; } if (FLAG(obj2.poserr_cxx)) { double xm2,ym2, xym, temp; xm2 = obj->poserr_mx2; ym2 = obj->poserr_my2; xym = obj->poserr_mxy; obj2->poserr_cxx = (float)(ym2/(temp=xm2*ym2-xym*xym)); obj2->poserr_cyy = (float)(xm2/temp); obj2->poserr_cxy = (float)(-2*xym/temp); } /* ---- Aspect ratio */ if (FLAG(obj2.elong)) obj2->elong = obj->a/obj->b; if (FLAG(obj2.ellip)) obj2->ellip = 1-obj->b/obj->a; if (FLAG(obj2.polar)) obj2->polar = (obj->a*obj->a - obj->b*obj->b) / (obj->a*obj->a + obj->b*obj->b); /*------------------------------- Photometry -------------------------------*/ /*-- Convert the father of photom. error estimates from variance to RMS */ obj2->flux_iso = obj->flux; obj2->fluxerr_iso = sqrt(obj->fluxerr); if (FLAG(obj.flux_prof)) { obj2->flux_prof = obj->flux_prof; obj2->fluxerr_prof = sqrt(obj->fluxerr_prof); } if (FLAG(obj2.flux_isocor)) computeisocorflux(field, obj); if (FLAG(obj2.flux_aper)) for (i=0; i<prefs.naper; i++) computeaperflux(field, wfield, obj, i); if (FLAG(obj2.flux_auto)) computeautoflux(field, dfield, wfield, dwfield, obj); if (FLAG(obj2.flux_petro)) computepetroflux(field, dfield, wfield, dwfield, obj); /*-- Growth curve */ if (prefs.growth_flag) makeavergrowth(field, wfield, obj); /*--------------------------- Windowed barycenter --------------------------*/ if (FLAG(obj2.winpos_x)) compute_winpos(field, wfield, obj); /*-- What about the peak of the profile? */ if (obj->peak+obj->bkg >= prefs.satur_level) obj->flag |= OBJ_SATUR; /*-- Check-image CHECK_APERTURES option */ if ((check = prefs.check[CHECK_APERTURES])) { if (FLAG(obj2.flux_aper)) for (i=0; i<prefs.naper; i++) sexcircle(check->pix, check->width, check->height, obj->mx, obj->my, prefs.apert[i]/2.0, check->overlay); if (FLAG(obj2.flux_auto)) sexellips(check->pix, check->width, check->height, obj->mx, obj->my, obj->a*obj2->kronfactor, obj->b*obj2->kronfactor, obj->theta, check->overlay, obj->flag&OBJ_CROWDED); if (FLAG(obj2.flux_petro)) sexellips(check->pix, check->width, check->height, obj->mx, obj->my, obj->a*obj2->petrofactor, obj->b*obj2->petrofactor, obj->theta, check->overlay, obj->flag&OBJ_CROWDED); } /* ---- Star/Galaxy classification */ if (FLAG(obj2.sprob)) { int j; double fac2, input[10], output, fwhm; fwhm = prefs.seeing_fwhm; fac2 = fwhm/field->pixscale; fac2 *= fac2; input[j=0] = log10(obj->iso[0]? obj->iso[0]/fac2: 0.01); input[++j] = field->thresh>0.0? log10(obj->peak>0.0? obj->peak/field->thresh: 0.1) :-1.0; for (i=1; i<NISO; i++) input[++j] = log10(obj->iso[i]? obj->iso[i]/fac2: 0.01); input[++j] = log10(fwhm); neurresp(input, &output); obj2->sprob = (float)output; } /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/ /*-- Put here your calls to "BLIND" custom functions. Ex: compute_myotherparams(obj); --*/ /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/ newnumber = ++thecat.ntotal; /*-- update segmentation map */ if ((check=prefs.check[CHECK_SEGMENTATION])) { ULONG *pix; ULONG newsnumber = newnumber, oldsnumber = obj->number; int dx,dx0,dy,dpix; pix = (ULONG *)check->pix + check->width*obj->ymin + obj->xmin; dx0 = obj->xmax-obj->xmin+1; dpix = check->width-dx0; for (dy=obj->ymax-obj->ymin+1; dy--; pix += dpix) for (dx=dx0; dx--; pix++) if (*pix==oldsnumber) *pix = newsnumber; } obj->number = newnumber; if (FLAG(obj2.vignet)) copyimage(field,outobj2.vignet,prefs.vignetsize[0],prefs.vignetsize[1], ix,iy); if (FLAG(obj2.vigshift)) copyimage_center(field, outobj2.vigshift, prefs.vigshiftsize[0], prefs.vigshiftsize[1], obj->mx, obj->my); /*--- Express everything in magnitude units */ computemags(field, obj); /*------------------------------- PSF fitting ------------------------------*/ nsub = 1; if (prefs.psf_flag) { psf_fit(thepsf, field, wfield, obj); obj2->npsf = thepsfit->npsf; if (prefs.psfdisplay_type == PSFDISPLAY_SPLIT) { nsub = thepsfit->npsf; if (nsub<1) nsub = 1; } else for (j=0; j<thepsfit->npsf; j++) { if (FLAG(obj2.x_psf) && j<prefs.psf_xsize) obj2->x_psf[j] = thepsfit->x[j]; if (FLAG(obj2.y_psf) && j<prefs.psf_ysize) obj2->y_psf[j] = thepsfit->y[j]; if (FLAG(obj2.flux_psf) && j<prefs.psf_fluxsize) obj2->flux_psf[j] = thepsfit->flux[j]; if (FLAG(obj2.mag_psf) && j<prefs.psf_magsize) obj2->mag_psf[j] = thepsfit->flux[j]>0.0? prefs.mag_zeropoint -2.5*log10(thepsfit->flux[j]) : 99.0; } } /*-------------------------------- Astrometry ------------------------------*/ if (prefs.world_flag) computeastrom(field, obj); /*-- Edit min and max coordinates to follow the FITS conventions */ obj->xmin += 1; obj->ymin += 1; obj->xmax += 1; obj->ymax += 1; /*-- Go through each newly identified component */ for (j=0; j<nsub; j++) { if (prefs.psf_flag && prefs.psfdisplay_type == PSFDISPLAY_SPLIT) { if (FLAG(obj2.x_psf)) obj2->x_psf[0] = thepsfit->x[j]; if (FLAG(obj2.y_psf)) obj2->y_psf[0] = thepsfit->y[j]; if (FLAG(obj2.flux_psf)) obj2->flux_psf[0] = thepsfit->flux[j]; if (FLAG(obj2.mag_psf)) obj2->mag_psf[0] = thepsfit->flux[j]>0.0? prefs.mag_zeropoint -2.5*log10(thepsfit->flux[j]) : 99.0; if (j) obj->number = ++thecat.ntotal; } FPRINTF(OUTPUT, "%8d %6.1f %6.1f %5.1f %5.1f %12g " "%c%c%c%c%c%c%c%c\n", obj->number, obj->mx+1.0, obj->my+1.0, obj->a, obj->b, obj->flux, obj->flag&OBJ_CROWDED?'C':'_', obj->flag&OBJ_MERGED?'M':'_', obj->flag&OBJ_SATUR?'S':'_', obj->flag&OBJ_TRUNC?'T':'_', obj->flag&OBJ_APERT_PB?'A':'_', obj->flag&OBJ_ISO_PB?'I':'_', obj->flag&OBJ_DOVERFLOW?'D':'_', obj->flag&OBJ_OVERFLOW?'O':'_'); writecat(n, objlist); } } if (prefs.user_ana) prefs.user_ana(obj, obj2); /* pour TOADS */ /* Remove again from the image the object's pixels if BLANKing is on ... */ /*-- ... and free memory */ if (prefs.blank_flag && obj->blank) { if (selecflag) { if (prefs.somfit_flag && (check=prefs.check[CHECK_MAPSOM])) blankcheck(check, obj->blank, obj->subw, obj->subh, obj->subx, obj->suby, (PIXTYPE)*(obj2->vector_somfit)); } blankimage(field, obj->blank, obj->subw, obj->subh, obj->subx, obj->suby, -BIG); free(obj->blank); if (obj->dblank) { blankimage(dfield, obj->dblank, obj->subw, obj->subh, obj->subx, obj->suby, -BIG); free(obj->dblank); } } return; }
/* =============================================================== */ int32_t l3disthmus(struct xvimage * f) /* =============================================================== */ /* detruit les isthmes 1D (T = 2 ; Tb = 1) */ #undef F_NAME #define F_NAME "l3disthmus" { struct xvimage * g; struct xvimage * fp; index_t rs, cs, ds, ps, N; index_t x; uint8_t *F; uint8_t *FP; #ifdef VERBOSE fprintf(stderr, "%s: Debut traitement\n", F_NAME); #endif g = allocimage(NULL, 7, 7, 7, VFF_TYP_1_BYTE); if (g == NULL) { fprintf(stderr,"%s : malloc failed\n", F_NAME); exit(0); } rs = rowsize(f); cs = colsize(f); ds = depth(f); F = UCHARDATA(f); ps = rs * cs; N = ps * ds; fp = copyimage(f); if (fp == NULL) { fprintf(stderr,"%s : copyimage failed\n", F_NAME); return 0; } FP = UCHARDATA(fp); for (x = 0; x < N; x++) { if (FP[x]) { int32_t tb; int32_t t = T3d(fp, x % rs, (x % ps) / rs, x / ps, g); if (t == 2) { tb = Tbar3d(fp, x % rs, (x % ps) / rs, x / ps, g); if (tb == 1) F[x] = 0; } #ifdef DEBUGISTHMUS printf("point %d %d %d : t = %d ; [tb = %d](si t==2) ; new val = %d\n", x % rs, (x % ps) / rs, x / ps, t, tb, F[x]); #endif } } freeimage(g); freeimage(fp); return 1; } /* l3disthmus() */
/* =============================================================== */ int32_t l3dskelsurf(struct xvimage * k, int32_t nsteps) /* =============================================================== */ /* squelette surfacique 3d dans la grille de Khalimsky */ #undef F_NAME #define F_NAME "l3dskelsurf" { struct xvimage * kp; int32_t stablealpha, stablebeta, i; index_t x, y, z; index_t rs, cs, ps, d, N; uint8_t * K; uint8_t * KP; rs = rowsize(k); cs = colsize(k); d = depth(k); ps = rs * cs; N = ps * d; K = UCHARDATA(k); #ifdef VERBOSE fprintf(stderr, "%s: Debut traitement\n", F_NAME); #endif InitPileGrilles3d(); kp = copyimage(k); if (kp == NULL) { fprintf(stderr,"%s : copyimage failed\n", F_NAME); return 0; } KP = UCHARDATA(kp); if (nsteps == -1) nsteps = 1000000000; for (i = 1; i <= nsteps; i++) { #ifdef VERBOSE fprintf(stderr, "step %d\n", i); #endif if (i % 2) { stablealpha = 1; for (z = 0; z < d; z++) for (y = 0; y < cs; y++) for (x = 0; x < rs; x++) if (K[z * ps + y * rs + x] && Alpha3Simple3d(k, x, y, z) && !Surfend3d(k, x, y, z)) { KP[z * ps + y * rs + x] = 0; stablealpha = 0; } memcpy(K, KP, N); } else { stablebeta = 1; for (z = 0; z < d; z++) for (y = 0; y < cs; y++) for (x = 0; x < rs; x++) if (K[z * ps + y * rs + x] && Beta3Simple3d(k, x, y, z) && !Surfend3d(k, x, y, z)) { KP[z * ps + y * rs + x] = 0; stablebeta = 0; } memcpy(K, KP, N); } if (stablealpha && stablebeta) break; } TerminePileGrilles3d(); freeimage(kp); return 1; } /* l3dskelsurf() */