Commit 550012d6 authored by Julien Michel's avatar Julien Michel
Browse files

ENH: Adding the EDISON implementation of the mean shift algorithm

parent 383c0d9b
......@@ -26,7 +26,7 @@ ENDIF(NOT OTB_USE_EXTERNAL_EXPAT)
#Supress libraries not used by the 2.2.0 version
#SUBDIRS(BGL otbsvm dxflib InsightJournal otbossim otb6S otbgeotiff tinyXMLlib otbgalib otbkml)
SUBDIRS(BGL otbsvm dxflib InsightJournal otbossim otb6S otbgeotiff tinyXMLlib otbkml otbliblas)
SUBDIRS(BGL otbsvm dxflib InsightJournal otbossim otb6S otbgeotiff tinyXMLlib otbkml otbliblas otbedison)
IF(BUILD_TESTING)
SUBDIRS( Dart )
......
SET(EDISON_SOURCE
prompt/parser.cpp
prompt/globalFnc.cpp
prompt/edison.cpp
prompt/libppm.cpp
segm/ms.cpp
segm/msSysPrompt.cpp
segm/msImageProcessor.cpp
segm/RAList.cpp
segm/rlist.cpp
edge/BgEdge.cpp
edge/BgEdgeDetect.cpp
edge/BgEdgeList.cpp
edge/BgGlobalFc.cpp
edge/BgImage.cpp)
SET(EDISON_HEADERS
prompt/parser.h
prompt/defs.h
prompt/error.h
prompt/flags.h
prompt/edison.h
prompt/imfilt.h
prompt/libppm.h
segm/tdef.h
segm/RAList.h
segm/ms.h
segm/msImageProcessor.h
segm/msSys.h
segm/rlist.h
edge/BgDefaults.h
edge/BgEdge.h
edge/BgEdgeDetect.h
edge/BgImage.h
)
ADD_LIBRARY(otbedison ${EDISON_SOURCE})
INSTALL(TARGETS otbedison
RUNTIME DESTINATION ${OTB_INSTALL_BIN_DIR} COMPONENT RuntimeLibraries
LIBRARY DESTINATION ${OTB_INSTALL_LIB_DIR} COMPONENT RuntimeLibraries
ARCHIVE DESTINATION ${OTB_INSTALL_LIB_DIR} COMPONENT Development)
INSTALL(FILES ${EDISON_HEADERS}
DESTINATION ${OTB_INSTALL_INCLUDE_DIR}/Utilities/otedison
COMPONENT Development)
/////////////////////////////////////////////////////////////////////////////
// Name: imagpnm.cpp
// Purpose: wxImage PNM handler
// Author: Sylvain Bougnoux
// RCS-ID: $Id: imagpnm.cpp,v 1.17 1999/12/15 22:38:02 VS Exp $
// Copyright: (c) Sylvain Bougnoux
// Licence: wxWindows licence
// Modified by: Bogdan Georgescu
// read gray pgm
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "BgImagPGM.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/setup.h"
#endif
#include "BgImagPGM.h"
#include <wx/log.h>
#include <wx/intl.h>
#include <wx/txtstrm.h>
//-----------------------------------------------------------------------------
// bgPGMHandler
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(bgPGMHandler,wxImageHandler)
void bgPGMHandler::Skip_Comment(wxInputStream &stream)
{
wxTextInputStream text_stream(stream);
if (stream.Peek()==wxT('#'))
{
text_stream.ReadLine();
Skip_Comment(stream);
}
}
bool bgPGMHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose, int WXUNUSED(index) )
{
wxUint32 width, height;
wxUint16 maxval;
char c(0);
image->Destroy();
/*
* Read the PGM header
*/
wxBufferedInputStream buf_stream(stream);
wxTextInputStream text_stream(buf_stream);
Skip_Comment(buf_stream);
if (buf_stream.GetC()==wxT('P')) c=buf_stream.GetC();
switch (c)
{
case wxT('2'):
case wxT('5'): break;
// case wxT('3'):
// case wxT('6'): break;
default:
if (verbose) wxLogError(_("PGM: File format is not recognized."));
return FALSE;
}
text_stream.ReadLine(); // for the \n
Skip_Comment(buf_stream);
text_stream >> width >> height ;
Skip_Comment(buf_stream);
text_stream >> maxval;
//cout << line << " " << width << " " << height << " " << maxval << endl;
image->Create( width, height );
unsigned char *ptr = image->GetData();
if (!ptr)
{
if (verbose)
wxLogError( _("PGM: Couldn't allocate memory.") );
return FALSE;
}
if (c=='2') // Ascii Gray
{
wxUint32 value, size=width*height;
for (wxUint32 i=0; i<size; ++i)
{
//this is very slow !!!
//I wonder how we can make any better ?
value=text_stream.Read32();
*ptr++=(unsigned char)value;
*ptr++=(unsigned char)value;
*ptr++=(unsigned char)value;
#if wxCHECK_VERSION(2, 3, 0)
if (!buf_stream)
#else
if (buf_stream.LastError()!=wxSTREAM_NOERROR)
#endif
{
if (verbose) wxLogError(_("PNM: File seems truncated."));
return FALSE;
}
}
}
if (c=='5') // Raw gray
{
buf_stream.Read( ptr, width*height );
// rearange
int i,idx;
int size = width*height;
idx = size*3-1;
for (i=(size-1); i>=0; i--)
{
ptr[idx--] = ptr[i];
ptr[idx--] = ptr[i];
ptr[idx--] = ptr[i];
}
}
image->SetMask( FALSE );
#if wxCHECK_VERSION(2, 3, 0)
const wxStreamError err = buf_stream.GetLastError();
return err == wxSTREAM_NO_ERROR || err == wxSTREAM_EOF;
#else
return (buf_stream.LastError()==wxStream_NOERROR || buf_stream.LastError()==wxStream_EOF);
#endif
}
bool bgPGMHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool WXUNUSED(verbose) )
{
//wxTextOutputStream text_stream(stream);
//text_stream << "P5" << endl
//<< image->GetWidth() << " " << image->GetHeight() << endl
//<< "255" << endl;
char header[70];
int width, height;
width = image->GetWidth();
height = image->GetHeight();
sprintf(header, "P5\n%d %d\n255\n", width, height);
stream.Write(header, strlen(header));
unsigned char *ptr = image->GetData();
// convert it to bw;
unsigned char *tptr;
tptr = new unsigned char[width*height];
int i,idx;
idx = 0;
for (i=0; i<width*height; i++)
{
tptr[i] = (unsigned char) (RED_WEIGHT*ptr[idx] + GREEN_WEIGHT*ptr[idx+1] + BLUE_WEIGHT*ptr[idx+2]);
idx += 3;
}
stream.Write(tptr,width*height);
delete [] tptr;
#if wxCHECK_VERSION(2, 3, 0)
return stream.IsOk();
#else
return (stream.LastError()==wxStream_NOERROR);
#endif
}
bool bgPGMHandler::DoCanRead( wxInputStream& stream )
{
off_t pos = stream.TellI();
Skip_Comment(stream);
if ( stream.GetC() == 'P' )
{
switch (stream.GetC())
{
case '2':
case '5':
stream.SeekI(pos);
return TRUE;
}
}
stream.SeekI(pos);
return FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// Name: imagpnm.h
// Purpose: wxImage PNM handler
// Author: Sylvain Bougnoux
// RCS-ID: $Id: imagpnm.h,v 1.1 1999/12/15 22:37:51 VS Exp $
// Copyright: (c) Sylvain Bougnoux
// Licence: wxWindows licence
// Modified by: Bogdan Georgescu
// read gray pgm
/////////////////////////////////////////////////////////////////////////////
#ifndef _BG_IMAGPGM_H_
#define _BG_IMAGPGM_H_
#ifdef __GNUG__
#pragma interface "BgImagPGM.h"
#endif
#include <wx/image.h>
//-----------------------------------------------------------------------------
// bgPGMHandler
//-----------------------------------------------------------------------------
#define RED_WEIGHT 0.299
#define GREEN_WEIGHT 0.587
#define BLUE_WEIGHT 0.114
class bgPGMHandler : public wxImageHandler
{
DECLARE_DYNAMIC_CLASS(bgPGMHandler)
public:
inline bgPGMHandler()
{
m_name = "PGM file";
m_extension = "pgm";
m_type = wxBITMAP_TYPE_ANY;
m_mime = "image/pgm";
};
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE, int index=0 );
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
virtual bool DoCanRead( wxInputStream& stream );
void Skip_Comment(wxInputStream &stream);
};
#endif
// _BG_IMAGPGM_H_
\ No newline at end of file
/////////////////////////////////////////////////////////////////////////////
// Name: imagpnm.cpp
// Purpose: wxImage PNM handler
// Author: Sylvain Bougnoux
// RCS-ID: $Id: imagpnm.cpp,v 1.17 1999/12/15 22:38:02 VS Exp $
// Copyright: (c) Sylvain Bougnoux
// Licence: wxWindows licence
// Modified by: Chris M. Christoudias
// read/write pnm images
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "BgImagPNM.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/setup.h"
#endif
#include "BgImagPNM.h"
#include <wx/log.h>
#include <wx/intl.h>
#include <wx/txtstrm.h>
#include <string.h>
#include <stdio.h>
//-----------------------------------------------------------------------------
// bgPGMHandler
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(bgPNMHandler,wxImageHandler)
void bgPNMHandler::Skip_Comment(wxInputStream &stream)
{
wxTextInputStream text_stream(stream);
if (stream.Peek()==wxT('#'))
{
text_stream.ReadLine();
Skip_Comment(stream);
}
}
bool bgPNMHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose, int WXUNUSED(index) )
{
wxUint32 width, height;
wxUint16 maxval;
char c(0);
image->Destroy();
/*
* Read the PGM header
*/
wxBufferedInputStream buf_stream(stream);
wxTextInputStream text_stream(buf_stream);
Skip_Comment(buf_stream);
if (buf_stream.GetC()==wxT('P')) c=buf_stream.GetC();
switch (c)
{
case wxT('2'):
case wxT('5'):
case wxT('6'): break;
default:
if (verbose) wxLogError(_("PGM: File format is not recognized."));
return FALSE;
}
text_stream.ReadLine(); // for the \n
Skip_Comment(buf_stream);
text_stream >> width >> height ;
Skip_Comment(buf_stream);
text_stream >> maxval;
//cout << line << " " << width << " " << height << " " << maxval << endl;
image->Create( width, height );
unsigned char *ptr = image->GetData();
if (!ptr)
{
if (verbose)
wxLogError( _("PNM: Couldn't allocate memory.") );
return FALSE;
}
if (c=='2') // Ascii Gray
{
wxUint32 value, size=width*height;
for (wxUint32 i=0; i<size; ++i)
{
//this is very slow !!!
//I wonder how we can make any better ?
value=text_stream.Read32();
*ptr++=(unsigned char)value;
*ptr++=(unsigned char)value;
*ptr++=(unsigned char)value;
#if wxCHECK_VERSION(2, 3, 0)
if (!buf_stream)
#else
if (buf_stream.LastError()!=wxSTREAM_NOERROR)
#endif
{
if (verbose) wxLogError(_("PNM: File seems truncated."));
return FALSE;
}
}
}
if (c=='5') // Raw gray
{
buf_stream.Read( ptr, width*height );
// rearange
int i,idx;
int size = width*height;
idx = size*3-1;
for (i=(size-1); i>=0; i--)
{
ptr[idx--] = ptr[i];
ptr[idx--] = ptr[i];
ptr[idx--] = ptr[i];
}
}
if (c=='6') // Raw color
{
buf_stream.Read( ptr, width*height*3 );
}
image->SetMask( FALSE );
#if wxCHECK_VERSION(2, 3, 0)
const wxStreamError err = buf_stream.GetLastError();
return err == wxSTREAM_NO_ERROR || err == wxSTREAM_EOF;
#else
return (buf_stream.LastError()==wxStream_NOERROR || buf_stream.LastError()==wxStream_EOF);
#endif
}
bool bgPNMHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool WXUNUSED(verbose) )
{
char header[70];
int width, height;
width = image->GetWidth();
height = image->GetHeight();
sprintf(header, "P6\n%d %d\n255\n", width, height);
stream.Write(header, strlen(header));
unsigned char *ptr = image->GetData();
stream.Write(ptr,width*height*3);
#if wxCHECK_VERSION(2, 3, 0)
return stream.IsOk();
#else
return (stream.LastError()==wxStream_NOERROR);
#endif
}
bool bgPNMHandler::DoCanRead( wxInputStream& stream )
{
off_t pos = stream.TellI();
Skip_Comment(stream);
if ( stream.GetC() == 'P' )
{
switch (stream.GetC())
{
case '2':
case '5':
case '6':
stream.SeekI(pos);
return TRUE;
}
}
stream.SeekI(pos);
return FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// Name: imagpnm.h
// Purpose: wxImage PNM handler
// Author: Sylvain Bougnoux
// RCS-ID: $Id: imagpnm.h,v 1.1 1999/12/15 22:37:51 VS Exp $
// Copyright: (c) Sylvain Bougnoux
// Licence: wxWindows licence
// Modified by: Chris M. Christoudias
// read/write pnm image
/////////////////////////////////////////////////////////////////////////////
#ifndef _BG_IMAGPNM_H_
#define _BG_IMAGPNM_H_
#ifdef __GNUG__
#pragma interface "BgImagPNM.h"
#endif
#include <wx/image.h>
//-----------------------------------------------------------------------------
// bgPGMHandler
//-----------------------------------------------------------------------------
class bgPNMHandler : public wxImageHandler
{
DECLARE_DYNAMIC_CLASS(bgPNMHandler)
public:
inline bgPNMHandler()
{
m_name = "PNM file";
m_extension = "pnm";
m_type = wxBITMAP_TYPE_PNM;
m_mime = "image/pnm";
};
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE, int index=0 );
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
virtual bool DoCanRead( wxInputStream& stream );
void Skip_Comment(wxInputStream &stream);
};
#endif
This diff is collapsed.
This diff is collapsed.
/* XPM */
static char *copy_xpm[] = {
/* columns rows colors chars-per-pixel */
"16 15 4 1",
" c None",
". c Black",
"X c Gray100",
"o c #000080",
/* pixels */
" ",
" ...... ",
" .XXXX.. ",
" .XXXX.X. ",
" .X..X.oooooo ",
" .XXXXXoXXXXoo ",
" .X....oXXXXoXo ",
" .XXXXXoX..Xoooo",
" .X....oXXXXXXXo",
" .XXXXXoX.....Xo",
" ......oXXXXXXXo",
" oX.....Xo",
" oXXXXXXXo",
" ooooooooo",
" "
};
/* XPM */
static char *cut_xpm[] = {
/* columns rows colors chars-per-pixel */
"16 15 3 1",
" c None",
". c Black",
"X c #000080",
/* pixels */
" ",
" . . ",
" . . ",
" . . ",
" .. .. ",
" . . ",
" ... ",
" . ",
" X.X ",
" X XXX ",
" XXX X X ",
" X X X X ",
" X X X X ",
" X X XX ",
" XX "
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment