Elaboradar 0.1
Caricamento in corso...
Ricerca in corso...
Nessun risultato

◆ write_subimage() [1/2]

void elaboradar::Assets::write_subimage ( const radarelab::Matrix2D< unsigned char > & image,
unsigned image_side,
const char * dir_env_var,
const char * ext,
const char * desc )

Write an image in a raw file in ${dir_env_var}, with the acquisition date as file name and the given extension.

Image matrix is tranformed in out_image(x,image.cols()-1-y) = image(y, x);

Parametri
[in]image- Matrix2D to be written
[in]image_side- write only the square central part of the original image, with this size in pixels of the image side
[in]dir_env_var- file path
[in]ext- file extension
[out]desc- used to get better error messages.

Definizione alla linea 569 del file assets.cpp.

570{
571 const char* dir = getenv(dir_env_var);
572 if (!dir)
573 {
574 LOG_INFO("$%s not set", dir_env_var);
575 throw runtime_error("required env var is not set");
576 }
577
578 string fname = string(dir) + "/" + fname_from_acq_time() + "_" + std::to_string(image_side) + ext;
579 FILE* out = fopen_checked(fname.c_str(), "wb", desc);
580
581 LOG_INFO("aperto file %s dimensione matrice %zd\n", fname.c_str(), image.size());
582
583 // Convert to south-north columns scanned west to east
584 unsigned xofs = (image.cols() - image_side) / 2;
585 unsigned yofs = (image.rows() - image_side) / 2;
586 //LOG_INFO(" Image_size %4d , Image.cols %4d Image.Rows %4d -- xofs %d yofs %d", image_side, image.cols(), image.rows(), xofs, yofs);
587 Matrix2D<unsigned char> transformed(image_side, image_side);
588 for (unsigned y = 0; y < image_side; ++y)
589 for (unsigned x = 0; x < image_side; ++x)
590 transformed(x, image_side-1-y) = image(y + yofs, x + xofs);
591
592 if (fwrite(transformed.data(), transformed.size(), 1, out) != 1)
593 {
594 LOG_WARN("cannot write to %s: %s", fname.c_str(), strerror(errno));
595 fclose(out);
596 throw std::runtime_error("cannot write to image file");
597 }
598
599 fclose(out);
600}
std::string fname_from_acq_time() const
Build a basename (without extension) for a file given the current acquisition time.
Definition assets.cpp:531
FILE * fopen_checked(const char *fname, const char *mode, const char *description)
A wrapper of fopen that throws an exception if it cannot open the file.
Definition utils.cpp:144
Base for all matrices we use, since we rely on row-major data.
Definition matrix.h:37

Referenzia fname_from_acq_time(), e radarelab::fopen_checked().