int main(int argc, char **argv) { MSG_native native; if (argc < 2) return 1; if (! native.open(argv[1])) return 1; native.read( ); std::cout << native.header; // native.pgmdump(1, "image.pgm"); unsigned short *pixels = native.data(native.IR_10_8_CHANNEL); Magick::Image *image = new Magick::Image( native.pixels(native.IR_10_8_CHANNEL), native.lines(native.IR_10_8_CHANNEL), "I", Magick::ShortPixel, pixels); image->normalize( ); image->rotate(180.0); image->write("image.jpg"); native.close( ); return 0; }
int main(int argc, char **argv) { MSG_native native; char *format; float gfactor; if (argc > 1) { if (!strcmp(argv[1], "-V")) { std::cout << argv[0] << " " << PACKAGE_STRING << std::endl; return 0; } } if (argc < 5) { std::cerr << "Usage: " << argv[0] << " file channel format scale" << std::endl; std::cerr << "Example: " << argv[0] << " MSG1-SEVI-MSG15-0100-NA-20040809131237.412000000Z-5766.nat" << " 8 gif 0.1" << std::endl; return -1; } int ichn = atoi(argv[2]); format = strdup(argv[3]); gfactor = atof(argv[4]); if (! native.open(argv[1])) { std::cerr << "Exit: Data Open Error." << std::endl; return -1; } native.read( ); Magick::Image *image = new Magick::Image(native.pixels(ichn), native.lines(ichn), "I", Magick::ShortPixel, native.data(ichn)); char outname[PATH_MAX]; snprintf(outname, PATH_MAX, "%s.%s", "MSG1", format); image->normalize( ); image->rotate(180.0); image->write(outname); Magick::Geometry geom((int) ((float) native.pixels(ichn)*gfactor), (int) ((float) native.lines(ichn) *gfactor)); image->scale(geom); native.close( ); return 0; }
// returns a masked version of given image where every pixel // above / below a given value ( in quantum range ) gets transparent Magick::Image masked( bool below, double value, Magick::Image img ) { Magick::Image mask = img; mask.type( Magick::GrayscaleMatteType ); mask.normalize(); double v = below ? value : 1-value; mask.threshold( v*MaxRGB ); if( below ) mask.negate(); mask.type( Magick::TrueColorMatteType ); mask.transparent( "black" ); Magick::Image masked = img; masked.composite( mask, Magick::CenterGravity, Magick::CopyOpacityCompositeOp ); return masked; }
int main (int argc, char *argv[]) { MSG_db1_data db1; char *format; char *image_overlay = 0; float gfactor; if (argc > 1) { if (!strcmp(argv[1], "-V")) { std::cout << argv[0] << " " << PACKAGE_STRING << std::endl; return 0; } } if (argc < 5) { std::cerr << "Usage: " << argv[0] << " directory channel format" << " scale [overlay image]" << std::endl; std::cerr << "Example: " << argv[0] << " dati IR_120 gif 0.1 SEVIRI_OVERLAY.pgm" << std::endl; return -1; } format = strdup(argv[3]); gfactor = atof(argv[4]); if (argc > 5) image_overlay = strdup(argv[5]); db1.open(argv[1]); if (! db1.has_channel(argv[2])) { std::cerr << "Exit: this channel is not present." << std::endl; return -1; } db1.set_channel(argv[2]); if (! db1.is_data_ok( )) { std::cerr << "Exit: Data Open Error." << std::endl; return -1; } char outname[PATH_MAX]; snprintf(outname, PATH_MAX, "%s_%s_%s.%s", db1.get_INFO_satellite_name( ), db1.get_channel_INFO_name( ), db1.get_INFO_schedule_start( ), format); for (int i = 0; i < (int) strlen(outname); i ++) { if (outname[i] == '/') outname[i] = '-'; if (outname[i] == ' ') outname[i] = '_'; if (outname[i] == ':') outname[i] = '-'; } Magick::Image *image = new Magick::Image(db1.get_INFO_image_pixels( ), db1.get_INFO_image_lines( ), "I", Magick::ShortPixel, db1.get_RAW_data( )); image->normalize( ); if (! db1.get_INFO_schedule_northsouth( )) image->rotate(180.0); if (image_overlay) { Magick::Image overlay; overlay.read("SEVIRI_OVERLAY.pgm"); image->composite(overlay, 0, 0, Magick::PlusCompositeOp); } Magick::Geometry geom((int) ((float) db1.get_INFO_image_pixels( )*gfactor), (int) ((float) db1.get_INFO_image_lines( )*gfactor)); image->scale(geom); image->write(outname); db1.close( ); return 0; }
void Magick::normalizeImage::operator()( Magick::Image &image_ ) const { image_.normalize( ); }
int main(int argc, char *argv[ ]) { char *directory = NULL; char *overlay_image = NULL; char *resolution = NULL; char *productid1 = NULL; char *productid2 = NULL; char *timing = NULL; char *format = NULL; char *pname = strdup(argv[0]); float geometry = 1.0; bool normalize = false; bool do_overlay = false; while (1) { int option_index = 0; int c; static struct option long_options[] = { {"directory", 1, 0, 'd'}, {"resolution", 1, 0, 'r'}, {"productid1", 1, 0, 's'}, {"productid2", 1, 0, 'c'}, {"outformat", 1, 0, 'f'}, {"outscale", 1, 0, 'g'}, {"overlay", 1, 0, 'o'}, {"time", 1, 0, 't'}, {"normalize", 0, 0, 'n'}, {"version", 0, 0, 'V'}, {"help", 0, 0, 'h'}, {0, 0, 0, 0} }; c = getopt_long (argc, argv, "d:r:s:c:f:g:o:t:nVh?", long_options, &option_index); if (c == -1) break; switch (c) { case 'd': directory = strdup(optarg); break; case 'r': resolution = strdup(optarg); break; case 's': productid1 = strdup(optarg); break; case 'c': productid2 = strdup(optarg); break; case 'f': format = strdup(optarg); break; case 'g': geometry = strtod(optarg, (char **)NULL); break; case 'o': do_overlay = true; overlay_image = strdup(optarg); break; case 't': timing = strdup(optarg); break; case 'n': normalize = true; break; case 'V': std::cout << pname << " " << PACKAGE_STRING << std::endl; return 0; case '?': case 'h': usage(pname); return(0); break; default: std::cerr << "?? getopt returned character code" << std::oct << c << "??" << std::endl; usage(pname); return(1); } } if (resolution == NULL || productid1 == NULL || productid2 == NULL || timing == NULL) { usage(pname); return(1); } std::string filename; if (directory) filename = directory; else filename = "."; filename = filename + PATH_SEPARATOR + resolution; filename = filename + "-\?\?\?-\?\?\?\?\?\?-"; filename = filename + underscoreit(productid1, 12) + "-"; filename = filename + underscoreit(productid2, 9) + "-"; filename = filename + "0\?\?\?\?\?___" + "-"; filename = filename + timing + "-" + "\?_"; glob_t globbuf; globbuf.gl_offs = 1; if ((glob(filename.c_str( ), GLOB_DOOFFS, NULL, &globbuf)) != 0) { std::cerr << "No such file(s)." << std::endl; return 1; } int nsegments = globbuf.gl_pathc; MSG_header *header; MSG_data *msgdat; header = new MSG_header[nsegments]; msgdat = new MSG_data[nsegments]; for (int i = 0; i < nsegments; i ++) { std::ifstream hrit(globbuf.gl_pathv[i+1], (std::ios::binary | std::ios::in)); if (hrit.fail()) { std::cerr << "Cannot open input hrit file " << globbuf.gl_pathv[i+1] << std::endl; return 1; } header[i].read_from(hrit); msgdat[i].read_from(hrit, header[i]); hrit.close( ); std::cout << header[i]; } globfree(&globbuf); if (header[0].segment_id->data_field_format == MSG_NO_FORMAT) { std::cout << "Product dumped in binary format." << std::endl; return 0; } int totalsegs = header[0].segment_id->planned_end_segment_sequence_number; int *segsindexes = new int[totalsegs]; for (int i = 0; i < totalsegs; i ++) segsindexes[i] = -1; for (int i = 0; i < nsegments; i ++) segsindexes[header[i].segment_id->sequence_number-1] = i; filename = resolution; filename = filename + "-" + productid1 + "-" + productid2 + "-" + timing; if (format) filename = filename + "." + format; else filename = filename + ".jpg"; int npix = header[0].image_structure->number_of_columns; int nlin = header[0].image_structure->number_of_lines; size_t npixperseg = npix*nlin; size_t total_size = totalsegs*npixperseg; MSG_SAMPLE *pixels = new MSG_SAMPLE[total_size]; memset(pixels, 0, total_size*sizeof(MSG_SAMPLE)); size_t pos = 0; for (int i = 0; i < totalsegs; i ++) { if (segsindexes[i] >= 0) memcpy(pixels+pos, msgdat[segsindexes[i]].image->data, npixperseg*sizeof(MSG_SAMPLE)); pos += npixperseg; } Magick::Image *image = new Magick::Image(npix, nlin*totalsegs, "I", Magick::ShortPixel, pixels); if (normalize) image->normalize( ); image->rotate(180.0); if (header[0].segment_id->spectral_channel_id < 12) { if (do_overlay) { Magick::Image overlay; overlay.read(overlay_image); image->composite(overlay, 0, 0, Magick::PlusCompositeOp); } } if (geometry < 1.0) { Magick::Geometry geom((int) ((float) npix*geometry), (int) ((float) nlin*totalsegs*geometry)); image->scale(geom); } image->write(filename); delete image; delete [ ] pixels; delete [ ] header; delete [ ] msgdat; delete [ ] segsindexes; return 0; }