diff --git a/README.md b/README.md index bb4ef80..3e4d0ca 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ To manually set the output filename Decode all WAV files in the current directory and put them in `images` ```sh -./aptdec -d images *.wav +mkdir images && ./aptdec -d images *.wav ``` Apply a denoise filter (see [Post-Processing Effects](#post-processing-effects) for a full list of post-processing effects) @@ -90,6 +90,7 @@ Apply a falsecolor palette - `d`: Denoise - `p`: Precipitation overlay - `f`: Flip image (for southbound passes) + - `c`: Crop noise from ends of image ## Realtime decoding @@ -116,4 +117,4 @@ Environmental Satellite Receiving Stations](https://noaasis.noaa.gov/NOAASIS/pub ## License -See `LICENSE` \ No newline at end of file +See `LICENSE` diff --git a/common.h b/common.h index e994fcc..06020c6 100644 --- a/common.h +++ b/common.h @@ -32,7 +32,7 @@ typedef struct { typedef struct { float *prow[MAX_HEIGHT]; // Row buffers int nrow; // Number of rows - int zenith; + int zenith; // Row in image where satellite reaches peak elevation int chA, chB; // ID of each channel char name[256]; // Stripped filename char *palette; // Filename of palette @@ -64,5 +64,6 @@ enum effects { Denoise='d', Precipitation_Overlay='p', Flip_Image='f', - Linear_Equalise='l' -}; \ No newline at end of file + Linear_Equalise='l', + Crop_Noise='c' +}; diff --git a/image.c b/image.c index c5a99ec..fd9b2b8 100644 --- a/image.c +++ b/image.c @@ -318,6 +318,54 @@ void flipImage(image_t *img, int width, int offset){ } } +// Calculate crop to reomve noise from the start and end of an image +void cropNoise(image_t *img){ + #define NOISE_THRESH 150.0 + + // Average value of minute marker + float spc_rows[MAX_HEIGHT] = { 0.0 }; + int startCrop = 0; int endCrop = img->nrow; + for(int y = 0; y < img->nrow; y++) { + for(int x = 0; x < SPC_WIDTH; x++) { + spc_rows[y] += img->prow[y][x + (CHB_OFFSET - SPC_WIDTH)]; + } + spc_rows[y] /= SPC_WIDTH; + + // Skip minute markings + if(spc_rows[y] < 10) { + spc_rows[y] = spc_rows[y-1]; + } + } + + // 3 row average + for(int y = 0; y < img->nrow; y++){ + spc_rows[y] = (spc_rows[y+1] + spc_rows[y+2] + spc_rows[y+3])/3; + //img.prow[y][0] = spc_rows[y]; + } + + // Find ends + for(int y = 0; y < img->nrow-1; y++) { + if(spc_rows[y] > NOISE_THRESH){ + endCrop = y; + } + } + for(int y = img->nrow; y > 0; y--) { + if(spc_rows[y] > NOISE_THRESH) { + startCrop = y; + } + } + + //printf("Crop rows: %i -> %i\n", startCrop, endCrop); + + // Remove the noisy rows at start + for(int y = 0; y < img->nrow-startCrop; y++) { + memmove(img->prow[y], img->prow[y+startCrop], sizeof(float)*2150); + } + + // Ignore the noisy rows at the end + img->nrow = (endCrop - startCrop); +} + // --- Temperature Calibration --- // #include "satcal.h" diff --git a/main.c b/main.c index c75f039..4019765 100644 --- a/main.c +++ b/main.c @@ -49,6 +49,7 @@ extern void temperature(options_t *opts, image_t *img, int offset, int width); extern void denoise(float **prow, int nrow, int offset, int width); extern void distrib(options_t *opts, image_t *img, char chid); extern void flipImage(image_t *img, int width, int offset); +extern void cropNoise(image_t *img); // Palettes extern char GviPalette[256*3]; @@ -144,7 +145,7 @@ static int processAudio(char *filename, options_t *opts){ char path[256], extension[32]; strcpy(path, filename); strcpy(path, dirname(path)); - sscanf(basename(filename), "%[^.].%s", img.name, extension); + sscanf(basename(filename), "%255[^.].%31s", img.name, extension); if(opts->realtime){ // Set output filename to current time when in realtime mode @@ -205,6 +206,11 @@ static int processAudio(char *filename, options_t *opts){ printf("Channel A: %s (%s)\n", ch.id[img.chA], ch.name[img.chA]); printf("Channel B: %s (%s)\n", ch.id[img.chB], ch.name[img.chB]); + // Crop noise from start and end of image + if(CONTAINS(opts->effects, Crop_Noise)){ + cropNoise(&img); + } + // Denoise if(CONTAINS(opts->effects, Denoise)){ denoise(img.prow, img.nrow, CHA_OFFSET, CH_WIDTH); @@ -318,7 +324,7 @@ static void usage(void) { fprintf(stderr, "Aptdec [options] audio files ...\n" "Options:\n" - " -i [r|a|b|t|m|p] Output image\n" + " -i [r|a|b|t|m|p] Output image\n" " r: Raw\n" " a: Channel A\n" " b: Channel B\n" @@ -332,11 +338,12 @@ static void usage(void) { " p: Precipitation\n" " f: Flip image\n" " l: Linear equalise\n" - " -o Output filename\n" + " c: Crop noise\n" + " -o Output filename\n" " -d Image destination directory.\n" " -s [15-19] Satellite number\n" " -m Map file\n" - " -p Path to palette\n" + " -p Path to palette\n" " -r Realtime decode\n" " -g Gamma adjustment (1.0 = off)\n" "\nRefer to the README for more infomation\n"); diff --git a/pngio.c b/pngio.c index 419647c..df916e9 100644 --- a/pngio.c +++ b/pngio.c @@ -350,12 +350,13 @@ int ImageOut(options_t *opts, image_t *img, int offset, int width, char *desc, c case Denoise: break; case Histogram_Equalise: break; case Linear_Equalise: break; + case Crop_Noise: break; default: fprintf(stderr, "NOTICE: Unrecognised effect, \"%c\"\n", opts->effects[i]); break; } } - + if(opts->map != NULL && opts->map[0] != '\0'){ greyscale = 0; }