1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
|
//==============================================================================
// Lynkeos
// $Id: MyListProcessing.h,v 1.14 2005/01/27 23:10:04 j-etienne Exp $
// Created by Jean-Etienne LAMIAUD on Fri Nov 07 2003.
//------------------------------------------------------------------------------
// Copyright (c) 2003-2005. Jean-Etienne LAMIAUD
//------------------------------------------------------------------------------
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
//------------------------------------------------------------------------------
/*!
* @header
* @abstract Threadable classes for image list processing
* @discussion The root class for threadable image list processing is
* MyListProcessing. Each concrete subclass implements a dedicated method to
* start the processing.
*/
#ifndef __MYLISTPROCESSING_H
#define __MYLISTPROCESSING_H
#import <Foundation/Foundation.h>
#include "MyImageListItem.h"
#include "processing_core.h"
/*!
* @class MyListProcessing
* @abstract Threadable wrapper class for image list processing
* @discussion It provides the thread environment to run legacy C routines
* dedicated to image processing.
*
* The objects arguments to thread messages are passed by address inside a
* NSData because we need the real object, not a proxy (it was never meant
* to be a distributed application ;o).
*
* The thread is created when the processing is started. It is done this way
* to ensure that the best processor is selected. Were the thread created at
* document opening, the load would vary on the processor where the thread
* runs, and could be unfavorable when a processing really starts.
* @ingroup Processing
*/
#define K_RX_PORT_KEY @"rxPort"
#define K_TX_PORT_KEY @"txPort"
@interface MyListProcessing : NSObject
{
@protected
MyIntegerRect _cropRectangle;
id _delegate;
NSEnumerator* _list;
RGB *_darkFrame;
RGB *_flatField;
bool _processEnded;
NSData* _result;
}
/*!
* @method threadWithAttributes:
* @abstract Thread creation
* @param attr Thread attributes : communication ports in a dictionary
* @discussion This method creates the thread, establishes the connection
* with the calling thread, starts a run loop and handle its autorelease pool.
*/
+ (void) threadWithAttributes:(NSDictionary*)attr ;
- (oneway void) stopProcessing ;
@end
/*!
* @class MyImageAligner
* @abstract Concrete MyListProcessing dedicated to image alignment
*/
@interface MyImageAligner : MyListProcessing
{
@private
NSLock* _refSpectrumLock;
MyImageListItem* _referenceItem;
FFT_DATA *_referenceSpectrum;
FFT_DATA _bufferSpectrum;
MyIntegerPoint _referenceOrigin;
u_short _side;
u_short _cutoff;
u_short _precisionThreshold;
BOOL _refSpectrumAvailable;
}
/*!
* @method alignWithList:darkFrame:flatField:reference:rectangle:cutOff:precisionThreshold:
* @abstract Start to align images in a list
* @param list An enumerator on the list of images to align
* @param refItem The reference image against which other images are aligned
* @param dark The stacked dark frames
* @param flat The stacked flat fields
* @param rect The default square in which alignment is searched (some images
* can have the square placed elsewhere).
* @param cutoff The frequency above which the spectrum is cleared to avoid
* spurious alignment on some systematic noise).
* @param threshold The threshold on the correlation peak standard deviation
* (above it, the alignment is considered failed).
* @discussion The reference item spectrum is computed and stored. After return
* from this method, the processing starts. For each selected item given by
* the enumerator, its spectrum is computed and used to correlate against the
* reference.
*
* The image data has the dark frame substracted from it, and is then
* divided by the flat field, before Fourier transform.
*
* The correlation peak is the alignment offset which is sent back to the
* calling thread by means of the processDidProgress delegate.
*/
- (oneway void) alignWithList:(NSData*)list reference:(NSData*)refItem
refBuffer:(NSData*)refSpectrum
lock:(NSData*)lock
darkFrame:(NSData*)dark flatField:(NSData*)flat
rectangle:(MyIntegerRect)rect
cutOff:(double)cutoff
precisionThreshold:(double)threshold;
@end
/*!
* @class MyImageAnalyzer
* @abstract Concrete MyListProcessing dedicated to image quality
*/
typedef enum
{
EntropyAnalysis,
SpectrumAnalysis
} MyAnalysisMethod;
@interface MyImageAnalyzer : MyListProcessing
{
u_short _side;
MyAnalysisMethod _method;
u_short _lowerCutoff;
u_short _upperCutoff;
FFT_DATA _bufferSpectrum;
}
/*!
* @method analyzeWithList:darkFrame:flatField:rectangle:lowCutoff:highCutoff:
* @abstract Start the analysis of the images in a list
* @param list An enumerator on the list of images to analyze
* @param dark The stacked dark frames
* @param flat The stacked flat fields
* @param rect The square in which the image is analyzed
* @param lCutoff Lower frequency cutoff (lower frequencies are not used)
* @param hCutoff high frequency cutoff (higher frequencies are not used)
* @discussion After return from this method, the processing starts. For each
* selected item given by the enumerator, its power spectrum is computed and
* integrated between lCutoff and hCutoff frequencies.
*
* The image data has the dark frame substracted from it, and is then
* divided by the flat field, before Fourier transform.
*
* The integrated value is the evaluated image quality which is sent back
* to the calling thread by means of the processDidProgress delegate.
*/
- (oneway void) analyzeWithList:(NSData*)list
darkFrame:(NSData*)dark flatField:(NSData*)flat
rectangle:(MyIntegerRect)rect
method:(MyAnalysisMethod)method
lowCutoff:(double)lCutoff highCutoff:(double)hCutoff ;
@end
/*!
* @class MyImageStack
* @abstract Concrete MyListProcessing dedicated to image stacking
*/
@interface MyImageStack : MyListProcessing
{
RGB* _rgbSum;
RGB* _rgbBuffer;
u_short _factor;
}
/*!
* @method stackWithList:darkFrame:flatField:rectangle:sizeFactor:
* @abstract Start to stack the images of a list
* @param list An enumerator on the list of images to stack
* @param dark The stacked dark frames
* @param flat The stacked flat fields
* @param rect The rectangle in which the images are stacked
* @param factor Homothetic factor for the stacked image
* @discussion After return from this method, the processing starts. For each
* selected and aligned item given by the enumerator, is cropped along the
* rectangle, expanded by factor and stacked with subpixel accuracy.
*
* The image data has the dark frame substracted from it, and is then
* divided by the flat field, before stacking.
*
* The calling thread is informed after each frame is added to the stack by
* means of the processDidProgress delegate.
*/
- (oneway void) stackWithList:(NSData*)list
darkFrame:(NSData*)dark flatField:(NSData*)flat
rectangle:(MyIntegerRect)rect
sizeFactor:(u_short)factor ;
@end
@protocol MyListProcessingDelegate
- (oneway void) processDidCreate :(id)obj ;
- (oneway void) processDidProgress :(NSData*)item data:(NSData*)what ;
- (oneway void) processDidFinish :(id)sender data:(NSData*)result;
@end
/*!
* @function normalize_rgb
* @abstract Multiply the pixels by a scalar
* @param rgb The sarray of rgb value to normalize
* @param length The array length
* @param scale The scale by wich the pixels will be multiplied. If 0, they will
* be multiplied by 1/max(rgb)
* @discussion This function is used for dark frames or flat fields, to
* normalize the stacking result according to its use (ie: dark frame stack
* shall be a mean value, and flat fields stack shall have its maximum
* equals to one).
*/
extern void normalize_rgb( RGB *rgb, u_long length, double scale, BOOL mono );
#endif
|