sp_matrix * sp_matrix_rotate(sp_matrix * in, SpAngle angleDef, int in_place){ double angle = 0; if(angleDef == sp_0Degrees){ return sp_matrix_duplicate(in); } sp_matrix * rot = sp_matrix_alloc(2,2); if(angleDef == sp_90Degrees){ angle = M_PI/2; } if(angleDef == sp_180Degrees){ angle = M_PI; } if(angleDef == sp_270Degrees){ angle = 3*M_PI/2; } if(in_place){ sp_error_fatal("In place rotation not implemented yet, sorry."); } if(sp_matrix_rows(in) != sp_matrix_cols(in)){ sp_error_fatal("Cannot rotate non square images, sorry."); } sp_matrix_set(rot,0,0,cos(angle)); sp_matrix_set(rot,0,1,sin(angle)); sp_matrix_set(rot,1,0,-sin(angle)); sp_matrix_set(rot,1,1,cos(angle)); sp_matrix * out = sp_matrix_duplicate(in); sp_matrix * newx = sp_matrix_alloc(sp_matrix_rows(in),sp_matrix_cols(in)); sp_matrix * newy = sp_matrix_alloc(sp_matrix_rows(in),sp_matrix_cols(in)); int min_x = 1e9; int min_y = 1e9; for(int x = 0;x < sp_matrix_rows(in);x++){ for(int y = 0;y < sp_matrix_cols(in);y++){ int new_x = round((x*sp_matrix_get(rot,0,0)+y*sp_matrix_get(rot,0,1))); int new_y = round((x*sp_matrix_get(rot,1,0)+y*sp_matrix_get(rot,1,1))); sp_matrix_set(newx,x,y,new_x); sp_matrix_set(newy,x,y,new_y); if(min_x > new_x){ min_x = new_x; } if(min_y > new_y){ min_y = new_y; } } } for(int i = 0;i<sp_matrix_size(newx);i++){ newx->data[i] -= min_x; newy->data[i] -= min_y; } for(int x = 0;x < sp_matrix_rows(in);x++){ for(int y = 0;y < sp_matrix_cols(in);y++){ sp_matrix_set(out,sp_matrix_get(newx,x,y),sp_matrix_get(newy,x,y),sp_matrix_get(in,x,y)); } } sp_matrix_free(newx); sp_matrix_free(newy); sp_matrix_free(rot); return out; }
void generate_poisson_noise(CCD * det){ #ifdef GSL_FOUND int i; init_random_generator(); if(!det->photons_per_pixel){ fprintf(stderr,"Please calculate photons per pixel first\n"); return; } det->photon_count = (float *)malloc(sizeof(float)*det->nx*det->ny*det->nz); for(i = 0;i<det->nx*det->ny*det->nz;i++){ if(det->photons_per_pixel[i]*det->quantum_efficiency < 1000){ det->photon_count[i] = get_poisson_random_number(det->photons_per_pixel[i]*det->quantum_efficiency); }else{ det->photon_count[i] = get_poisson_gaussian_approximate_random_number(det->photons_per_pixel[i]*det->quantum_efficiency); } } #else sp_error_fatal("spsim not compiled with GSL support"); #endif }