Opened 19 years ago

Closed 15 years ago

#993 closed defect (fixed)

Nearest Neighbor failes for 8 bit images — at Version 1

Reported by: james.e.hopper@… Owned by: gpotts
Priority: high Milestone:
Component: Algorithms/Functionality Version: 1.5.7
Severity: blocker Keywords:
Cc:

Description (last modified by mlucas17)

NN should  not create any pixel values in a file that do not already exist in that file as it is supposed to 
copy the nearest value.  but if i try to use it on an eight bit image the histogram after the resample 
shows that there are new values.  for example i created a file which has single black square in the 
middle of a white document.  histogram before resample shows 2 values (white and black) after 
resample there are several new values. they appear to be gray pixels around the edge of the square.  
below is a stupid small program i wrote to do a resample.  I use ossim with files like usgs landcover 
data and when i resample with ossim i get new values for pixel categories after the resample.


#include <iostream>
#include <fstream>

#include <ossim/ossimConfig.h>
#ifdef HAVE_GETOPT_H
#  if HAVE_GETOPT_H
#    include <getopt.h>
#  endif
#endif

#include <ossim/ossimString.h>
#include <ossim/ossimFilename.h>
#include <ossim/ossimIrect.h>
#include <ossim/ossimDatum.h>
#include <ossim/ossimProjectionFactoryRegistry.h>
#include <ossim/ossimProjection.h>


#include "ossim/ossimTiffTileSource.h"
#include "ossim/ossimStdOutProgress.h"
#include <ossim/ossimImageHandlerRegistry.h>
#include <ossim/ossimImageHandler.h>
#include "ossim/ossimImageFileWriter.h"

#include "ossim/ossimImageWriterFactoryRegistry.h"
#include "ossim/ossimInit.h"
#include "ossim/ossimCacheTileSource.h"
#include "ossim/ossimImageMosaic.h"
#include "ossim/ossimImageRenderer.h"
#include <ossim/ossimFilterResampler.h>
#include "ossim/ossimMapProjection.h"
#include "ossim/ossimDpt.h"
	

int main(int argc, char* argv[])
{
  
   ossimInit::instance()->initialize(argc, argv);
  ossimImageHandler *handler   = ossimImageHandlerRegistry::instance()->open(ossimFilename(argv
[2]));
  ossimImageFileWriter* writer = ossimImageWriterFactoryRegistry::instance()->createWriter
(ossimString(argv[1]));

  if(handler)
    {
		ossimCacheTileSource* cache = new ossimCacheTileSource();
		cache->connectMyInputTo(0, handler);
	  ((ossimTiffTileSource*)handler)->setApplyColorPaletteFlag(false);
		cache->setCachingEnabledFlag(false);
		ossimImageMosaic* mosaic = new ossimImageMosaic();
		mosaic->connectMyInputTo(0, cache);
		ossimImageRenderer* render = new ossimImageRenderer();
		render->connectMyInputTo(0, mosaic);
		ossimFilterResampler* rs = render->getResampler();
		rs->setFilterType(ossimFilterResampler::ossimFilterResampler_NEAREST_NEIGHBOR);
		
		ossimMapProjection* proj = (ossimMapProjection*)render->getView();
		ossimDpt* dPt = new ossimDpt( 2.44140625e-4, 2.44140625e-4);
		proj->setDecimalDegreesPerPixel(*dPt);
		render->setView(proj);
		
     // specify the output file name
      writer->setFilename(ossimFilename(argv[3]));
      writer->connectMyInputTo(0, render);
      ossimStdOutProgress progress(0, true);
      writer->addListener(&progress);
      writer->execute();

      // now to be on the safe side we will remove any added listeners.
      writer->removeListener(&progress);
      
      delete writer;
      delete handler;
      handler = 0;
    }

  return 0;
}

Change History (1)

comment:1 by mlucas17, 15 years ago

Description: modified (diff)
Resolution: fixed
Status: newclosed

Cleaning up trac ticket base. Do not believe there is a current issue with the NN resampling. Closing.

Note: See TracTickets for help on using tickets.