ports/118388: New port: graphics/pfscalibration Photometric calibration of cameras and recovery HDR images from the set of LDR exposures

Iouri V. Ivliev ii at any.com.ru
Sun Dec 2 18:20:01 UTC 2007


>Number:         118388
>Category:       ports
>Synopsis:       New port: graphics/pfscalibration Photometric calibration of cameras and recovery HDR images from the set of LDR exposures
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Dec 02 18:20:00 UTC 2007
>Closed-Date:
>Last-Modified:
>Originator:     Iouri V. Ivliev
>Release:        FreeBSD 6.2-RELEASE-p7 i386
>Organization:
EsterDev, Ltd.
>Environment:
System: FreeBSD smaug.esterdev.com 6.2-RELEASE-p7 FreeBSD 6.2-RELEASE-p7 #0: Sun Sep 23 17:28:25 UTC 2007 root at smaug.esterdev.com:/usr/obj/usr/src/sys/SMAUG i386
>Description:
PFScalibration package provides an implementation of the Robertson
et al. 2003 method for the photometric calibration of cameras and
for the recovery of high dynamic range (HDR) images from the set
of low dynamic range (LDR) exposures.

WWW: http://www.mpii.mpg.de/resources/hdr/calibration/pfs.html
>How-To-Repeat:
>Fix:
--- pfscalibration.shar begins here ---
# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	graphics/pfscalibration
#	graphics/pfscalibration/files
#	graphics/pfscalibration/files/patch-src-jpeg2hdrgen
#	graphics/pfscalibration/files/patch-src-pfshdrcalibrate.cpp
#	graphics/pfscalibration/files/patch-src-robertson02.cpp
#	graphics/pfscalibration/files/patch-src-robertson02.h
#	graphics/pfscalibration/Makefile
#	graphics/pfscalibration/distinfo
#	graphics/pfscalibration/pkg-descr
#	graphics/pfscalibration/pkg-plist
#
echo c - graphics/pfscalibration
mkdir -p graphics/pfscalibration > /dev/null 2>&1
echo c - graphics/pfscalibration/files
mkdir -p graphics/pfscalibration/files > /dev/null 2>&1
echo x - graphics/pfscalibration/files/patch-src-jpeg2hdrgen
sed 's/^X//' >graphics/pfscalibration/files/patch-src-jpeg2hdrgen << 'END-of-graphics/pfscalibration/files/patch-src-jpeg2hdrgen'
X--- src/jpeg2hdrgen.orig	Wed Aug 23 07:25:58 2006
X+++ src/jpeg2hdrgen	Thu Jun 21 14:34:33 2007
X@@ -28,18 +28,25 @@
X export LC_ALL
X 
X 
X-JHEAD="jhead"                   # program for extracting exif info from jpegs
X-
X-TEST_JHEAD=`which jhead`;
X-if [ "$TEST_JHEAD" = "" ]; then
X-    echo "Program 'jhead' is required to run this script."
X-    echo "Install appropriate software, for example from:"
X-    echo "http://www.sentex.net/~mwandel/jhead/"
X+JHEAD='jhead'                   # program for extracting exif info from jpegs
X+EXIF='exif'                     # another one
X+EXIV2='exiv2'                   # and one more
X+
X+CMD=`which ${JHEAD}`
X+[ -n "${CMD}" ] || CMD=`which ${EXIF}`
X+[ -n "${CMD}" ] || CMD=`which ${EXIV2}`
X+if [ -z "${CMD}" ]
X+then
X+    cat <<MSG
X+One of the following commands are required to run this script:
X+ '${JHEAD}' - stand-alone program (http://www.sentex.net/~mwandel/jhead/)
X+ '${EXIF}'  - part of libexif project (http://sf.net/projects/libexif/)
X+ '${EXIV2}' - part of exiv2 project (http://www.exiv2.org/)
X+MSG
X     exit 1;
X fi
X 
X-#Note: Double backslash MUST be put in front of each $ sign
X-AWK_PROGRAM=`cat <<EOF
X+AWK_PROGRAM='
X BEGIN {
X   exposure="";
X   aperture="";
X@@ -58,23 +65,49 @@
X     print exposure " " aperture " " iso_speed " 0";
X }
X 
X+## jhead output
X /^Exposure time: ([0-9]*\.[0-9]) */ {
X-  exposure = 1/\\$3;
X+  exposure = 1/$3;
X }
X-
X /^Aperture *: f\/([0-9]*\.[0-9]*)/ {
X-  aperture = substr(\\$3,3);
X+  aperture = substr($3,3);
X }
X-
X /^ISO equiv. *: ([0-9]*\.?[0-9]*)/ {
X-  iso_speed = \\$4;
X+  iso_speed = $4;
X }
X 
X-EOF`
X+## exif output
X+/^Exposure Time *\|.+ sec\./ {
X+  if (split(substr($3,2),a,"/") == 2)
X+    exposure = a[2];
X+  else
X+    exposure = 1/a[1];
X+}
X+/^FNumber *\|f\/.+/ {
X+    aperture = substr($2,4);
X+}
X+/^ISO Speed Ratings *\|.+/ {
X+    iso_speed = substr($4,2);
X+}
X 
X-while [ "$1" != "" ]; do
X-    EXPOSURE_INFO=`$JHEAD $1 | awk "$AWK_PROGRAM"`
X-    echo $1 $EXPOSURE_INFO
X+## exiv2 output
X+/^Exposure time *: .+ s/ {
X+  if (split($4,a,"/") == 2)
X+    exposure = a[2];
X+  else
X+    exposure = 1/a[1];
X+}
X+/^Aperture *: F.+/ {
X+    aperture = substr($3,2);
X+}
X+/^ISO speed *: .+/ {
X+    iso_speed = $4;
X+}
X+'
X 
X+while [ ${#} -ne 0 ]
X+do
X+    printf "${1} "
X+    ${CMD} "${1}" | awk "${AWK_PROGRAM}"
X     shift
X done 
END-of-graphics/pfscalibration/files/patch-src-jpeg2hdrgen
echo x - graphics/pfscalibration/files/patch-src-pfshdrcalibrate.cpp
sed 's/^X//' >graphics/pfscalibration/files/patch-src-pfshdrcalibrate.cpp << 'END-of-graphics/pfscalibration/files/patch-src-pfshdrcalibrate.cpp'
X--- src/pfshdrcalibrate.cpp.orig	Wed Aug 23 14:49:59 2006
X+++ src/pfshdrcalibrate.cpp	Thu Jun 21 14:40:28 2007
X@@ -108,7 +108,7 @@
X     { "help", no_argument, NULL, 'h' },
X     { "verbose", no_argument, NULL, 'v' },
X     { "luminance", no_argument, NULL, 'Y' },
X-    { "fillin-response", no_argument, NULL, 'F' },
X+//    { "fillin-response", no_argument, NULL, 'F' },
X     { "calibration", required_argument, NULL, 'c' },
X     { "gauss", required_argument, NULL, 'g' },
X     { "max-response", required_argument, NULL, 'A' },
X@@ -123,7 +123,7 @@
X 
X   int optionIndex = 0;
X   while( 1 ) {
X-    int c = getopt_long (argc, argv, "hvYFc:g:r:f:s:m:b:", cmdLineOptions, &optionIndex);
X+    int c = getopt_long (argc, argv, "hvYFc:g:r:f:s:m:b:S:A:", cmdLineOptions, &optionIndex);
X     if( c == -1 ) break;
X     switch( c ) {
X     case 'h':
X@@ -246,8 +246,8 @@
X     throw pfs::Exception("calibration method not set or not supported");
X   }
X 
X-  VERBOSE_STR << "interpolate missing parts of response: "
X-              << (opt_fillgaps ? "yes" : "no") << endl;
X+//   VERBOSE_STR << "interpolate missing parts of response: "
X+//               << (opt_fillgaps ? "yes" : "no") << endl;
X   
X   if( responseSaveFile!=NULL )
X     VERBOSE_STR << "save response curve to a file (do not generate HDR image)" << endl;
X@@ -434,6 +434,8 @@
X   pfs::Channel *Xj, *Yj, *Zj;
X   frame->createXYZChannels( Xj, Yj, Zj );
X 
X+  // !!! this currently does more bad than good, relevant command line
X+  // option is disabled
X   if( opt_fillgaps )
X   {
X     if( opt_luminance )
X@@ -453,42 +455,50 @@
X   }
X 
X   // calibration
X+  long sp = 0;                  // saturated pixels
X   switch( opt_calibration )
X   {
X   case NONE:
X     if( opt_luminance )
X     {
X       VERBOSE_STR << "applying response to Y channel..." << endl;
X-      robertson02_applyResponse( Yj, imgsY, Iy, w, M);
X+      sp = robertson02_applyResponse( Yj, imgsY, Iy, w, M);
X     }
X     else
X     {
X       VERBOSE_STR << "applying response to R channel..." << endl;
X-      robertson02_applyResponse( Xj, imgsR, Ir, w, M);
X+      sp = robertson02_applyResponse( Xj, imgsR, Ir, w, M);
X       VERBOSE_STR << "applying response to G channel..." << endl;
X-      robertson02_applyResponse( Yj, imgsG, Ig, w, M);
X+      sp += robertson02_applyResponse( Yj, imgsG, Ig, w, M);
X       VERBOSE_STR << "applying response to B channel..." << endl;
X-      robertson02_applyResponse( Zj, imgsB, Ib, w, M);
X+      sp += robertson02_applyResponse( Zj, imgsB, Ib, w, M);
X+      sp /= 3;
X     }
X     break;
X   case ROBERTSON:
X     if( opt_luminance )
X     {
X       VERBOSE_STR << "recovering Y channel..." << endl;
X-      robertson02_getResponse( Yj, imgsY, Iy, w, M);
X+      sp = robertson02_getResponse( Yj, imgsY, Iy, w, M);
X     }
X     else
X     {
X       VERBOSE_STR << "recovering R channel..." << endl;
X-      robertson02_getResponse( Xj, imgsR, Ir, w, M);
X+      sp = robertson02_getResponse( Xj, imgsR, Ir, w, M);
X       VERBOSE_STR << "recovering G channel..." << endl;
X-      robertson02_getResponse( Yj, imgsG, Ig, w, M);
X+      sp += robertson02_getResponse( Yj, imgsG, Ig, w, M);
X       VERBOSE_STR << "recovering B channel..." << endl;
X-      robertson02_getResponse( Zj, imgsB, Ib, w, M);
X+      sp += robertson02_getResponse( Zj, imgsB, Ib, w, M);
X+      sp /= 3;
X     }
X     break;
X   case DEBEVEC:
X     break;
X+  }
X+  if( sp>0 )
X+  {
X+    float perc = ceilf(100.0f*sp/size);
X+    VERBOSE_STR << "saturated pixels found in " << perc << "% of the image!" << endl;
X   }
X 
X   // save response curve to a given file
END-of-graphics/pfscalibration/files/patch-src-pfshdrcalibrate.cpp
echo x - graphics/pfscalibration/files/patch-src-robertson02.cpp
sed 's/^X//' >graphics/pfscalibration/files/patch-src-robertson02.cpp << 'END-of-graphics/pfscalibration/files/patch-src-robertson02.cpp'
X--- src/robertson02.cpp.orig	Thu Mar 16 12:22:46 2006
X+++ src/robertson02.cpp	Thu Jun 21 14:34:34 2007
X@@ -50,7 +50,7 @@
X float normalizeI( float* I, int M );
X 
X 
X-void robertson02_applyResponse( pfs::Array2D* xj, const ExposureList &imgs, 
X+int robertson02_applyResponse( pfs::Array2D* xj, const ExposureList &imgs, 
X   const float* I, const float* w, int M )
X {
X   // number of exposures
X@@ -59,6 +59,58 @@
X   // frame size
X   int width = xj->getCols();
X   int height = xj->getRows();
X+
X+  // number of saturated pixels
X+  int saturated_pixels = 0;
X+
X+  // --- anti saturation: calculate trusted camera output range
X+  int minM = 0;
X+  for( int m=0 ; m<M ; m++ )
X+    if( w[m]>0 )
X+    {
X+      minM = m;
X+      break;
X+    }
X+  int maxM = M-1;
X+  for( int m=M-1 ; m>=0 ; m-- )
X+    if( w[m]>0 )
X+    {
X+      maxM = m;
X+      break;
X+    }
X+  
X+  // --- anti ghosting: for each image i, find images with
X+  // the immediately higher and lower exposure times
X+  int* i_lower = new int[N];
X+  int* i_upper = new int[N];
X+  for( int i=0 ; i<N ; i++ )
X+  {
X+    i_lower[i]=-1;
X+    i_upper[i]=-1;
X+    float ti = imgs[i].ti;
X+    float ti_upper = imgs[0].ti;
X+    float ti_lower = imgs[0].ti;
X+
X+    for( int j=0 ; j<N ; j++ )
X+      if( i!=j )
X+      {
X+        if( imgs[j].ti>ti && imgs[j].ti<ti_upper )
X+        {
X+          ti_upper=imgs[j].ti;
X+          i_upper[i]=j;
X+        }
X+        if( imgs[j].ti<ti && imgs[j].ti>ti_lower )
X+        {
X+          ti_lower=imgs[j].ti;
X+          i_lower[i]=j;
X+        }
X+      }
X+    if( i_lower[i]==-1 )
X+      i_lower[i]=i;
X+    if( i_upper[i]==-1 )
X+      i_upper[i]=i;
X+  }
X+  
X   
X   // all pixels
X   for( int j=0 ; j<width*height ; j++ )
X@@ -66,36 +118,64 @@
X     // all exposures for each pixel
X     float sum = 0.0f;
X     float div = 0.0f;
X+
X+    float maxti = -1e6f;
X+    float minti = +1e6f;
X+    
X     for( int i=0 ; i<N ; i++ )
X     {
X       int m = (int) (*imgs[i].yi)(j);
X       float ti = imgs[i].ti;
X+
X+      // --- anti saturation: observe minimum exposure time at which
X+      // saturated value is present, and maximum exp time at which
X+      // black value is present
X+      if( m>maxM )
X+        minti = fminf(minti,ti);
X+      if( m<minM )
X+        maxti = fmaxf(maxti,ti);
X+      
X+      // --- anti ghosting: monotonous increase in time should result
X+      // in monotonous increase in intensity; make forward and
X+      // backward check, ignore value if condition not satisfied
X+      int m_lower = (int) (*imgs[i_lower[i]].yi)(j);
X+      int m_upper = (int) (*imgs[i_upper[i]].yi)(j);
X+      if( m_lower>m || m_upper<m)
X+        continue;
X+      
X       sum += w[m] * ti * I[m];
X       div += w[m] * ti * ti;
X     }
X 
X-    // This part does not work so well
X-//     if( sum < 1e-4 ) {
X-//       // If there is not enough information to restore luminance
X-//       // (saturated pixels), do not use weighting function
X-//       for( int i=0 ; i<N ; i++ )
X-//       {
X-//         int m = (int) (*imgs[i].yi)(j);
X-//         float ti = imgs[i].ti;
X-//         sum += ti * I[m];
X-//         div += ti * ti;
X-//       }
X-//     }
X-    
X+    // --- anti saturation: if a meaningful representation of pixel
X+    // was not found, replace it with information from observed data
X+    if( div==0.0f )
X+      saturated_pixels++;
X+    if( div==0.0f && maxti>-1e6f )
X+    {
X+      sum = I[minM];
X+      div = maxti;
X+    }
X+    if( div==0.0f && minti<+1e6f )
X+    {
X+      sum = I[maxM];
X+      div = minti;
X+    }
X+      
X     if( div!=0.0f )
X       (*xj)(j) = sum/div;
X     else
X       (*xj)(j) = 0.0f;
X   }
X+
X+  delete[] i_lower;
X+  delete[] i_upper;
X+  
X+  return saturated_pixels;
X }
X 
X 
X-void robertson02_getResponse( pfs::Array2D* xj, const ExposureList &imgs,
X+int robertson02_getResponse( pfs::Array2D* xj, const ExposureList &imgs,
X   float* I, const float* w, int M )
X {
X   // number of exposures
X@@ -105,6 +185,9 @@
X   int width = imgs[0].yi->getCols();
X   int height = imgs[0].yi->getRows();
X 
X+  // number of saturated pixels
X+  int saturated_pixels = 0;
X+
X   // indexes
X   int i,j,m;
X   
X@@ -160,7 +243,7 @@
X     float middle_response = normalizeI( I, M );
X 
X     // 3. Apply new response
X-    robertson02_applyResponse( xj, imgs, I, w, M );
X+    saturated_pixels = robertson02_applyResponse( xj, imgs, I, w, M );
X 
X     // 4. Check stopping condition
X     float delta = 0.0f;
X@@ -198,6 +281,8 @@
X   delete[] Ip;
X   delete[] cardEm;
X   delete[] sum;
X+  
X+  return saturated_pixels;
X }
X 
X 
END-of-graphics/pfscalibration/files/patch-src-robertson02.cpp
echo x - graphics/pfscalibration/files/patch-src-robertson02.h
sed 's/^X//' >graphics/pfscalibration/files/patch-src-robertson02.h << 'END-of-graphics/pfscalibration/files/patch-src-robertson02.h'
X--- src/robertson02.h.orig	Thu Mar 16 12:22:46 2006
X+++ src/robertson02.h	Thu Jun 21 14:34:34 2007
X@@ -39,8 +39,9 @@
X  * @param I [out] array to put response function
X  * @param w weights
X  * @param M max camera output (no of discrete steps)
X+ * @return number of saturated pixels in the HDR image (0: all OK)
X  */
X-void robertson02_getResponse( pfs::Array2D* xj, const ExposureList &imgs,
X+int robertson02_getResponse( pfs::Array2D* xj, const ExposureList &imgs,
X   float* I, const float* w, int M );
X 
X 
X@@ -53,8 +54,9 @@
X  * @param I camera response function (array size of M)
X  * @param w weighting function for camera output values (array size of M)
X  * @param M number of camera output levels
X+ * @return number of saturated pixels in the HDR image (0: all OK)
X  */
X-void robertson02_applyResponse( pfs::Array2D* xj, const ExposureList &imgs, 
X+int robertson02_applyResponse( pfs::Array2D* xj, const ExposureList &imgs, 
X   const float* I, const float* w, int M );
X 
X 
END-of-graphics/pfscalibration/files/patch-src-robertson02.h
echo x - graphics/pfscalibration/Makefile
sed 's/^X//' >graphics/pfscalibration/Makefile << 'END-of-graphics/pfscalibration/Makefile'
X# New ports collection makefile for:   pfscalibration
X# Date created:        Fri Jun  1 15:44:40 UTC 2007
X# Whom:                argv[0] (Iouri V. Ivliev)
X#
X# $FreeBSD$
X
XPORTNAME=	pfscalibration
XPORTVERSION=	1.3
XPORTREVISION=	1
XCATEGORIES=	graphics
XMASTER_SITES=	SF
XMASTER_SITE_SUBDIR= pfstools
X
XMAINTAINER=	ii at any.com.ru
XCOMMENT=	Photometric calibration of cameras and recovery HDR images from the set of LDR exposures
X
XPFS_CPPFLAGS=	-I${LOCALBASE}/include
XPFS_LDFLAGS=	-L${LOCALBASE}/lib
X
XGNU_CONFIGURE=	yes
XCONFIGURE_TARGET=	--build=${MACHINE_ARCH}-portbld-freebsd${OSREL}
XCONFIGURE_ENV=	CPPFLAGS="${PFS_CPPFLAGS}" \
X		LDFLAGS="${PFS_LDFLAGS}"
XUSE_GMAKE=	yes
XUSE_PERL5=	yes
X
XLIB_DEPENDS=	pfs-1.2:${PORTSDIR}/graphics/pfstools
X
XMAN1=		jpeg2hdrgen.1 \
X		dcraw2hdrgen.1 \
X		pfsinhdrgen.1 \
X		pfshdrcalibrate.1
X
X.include <bsd.port.mk>
END-of-graphics/pfscalibration/Makefile
echo x - graphics/pfscalibration/distinfo
sed 's/^X//' >graphics/pfscalibration/distinfo << 'END-of-graphics/pfscalibration/distinfo'
XMD5 (pfscalibration-1.3.tar.gz) = 5a08ec634cf53b105f412a826a2c2451
XSHA256 (pfscalibration-1.3.tar.gz) = 4ced5e1ff45a9e3a02592b002c008c2c974b9d80762198e71e678e4c16e1b754
XSIZE (pfscalibration-1.3.tar.gz) = 306650
END-of-graphics/pfscalibration/distinfo
echo x - graphics/pfscalibration/pkg-descr
sed 's/^X//' >graphics/pfscalibration/pkg-descr << 'END-of-graphics/pfscalibration/pkg-descr'
XPFScalibration package provides an implementation of the Robertson
Xet al. 2003 method for the photometric calibration of cameras and
Xfor the recovery of high dynamic range (HDR) images from the set
Xof low dynamic range (LDR) exposures.
X
XWWW: http://www.mpii.mpg.de/resources/hdr/calibration/pfs.html
END-of-graphics/pfscalibration/pkg-descr
echo x - graphics/pfscalibration/pkg-plist
sed 's/^X//' >graphics/pfscalibration/pkg-plist << 'END-of-graphics/pfscalibration/pkg-plist'
Xbin/pfshdrcalibrate
Xbin/jpeg2hdrgen
Xbin/dcraw2hdrgen
Xbin/pfsinhdrgen
END-of-graphics/pfscalibration/pkg-plist
exit
--- pfscalibration.shar ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the freebsd-ports-bugs mailing list