#include <image.h>
Inheritance diagram for ImageValue:
Public Member Functions | |
virtual Data | getSaveDescription (QString) |
ImageValue (int xs, int ys, int c) | |
ImageValue (PointValue topleft, PointValue bottomright, PointValue resolution, int channels) | |
ImageValue (QImage &i) | |
ImageValue (QString str) | |
ImageValue (Token data) | |
ImageValue * | deepCopy () |
virtual QString | toString () |
virtual bool | equals_same_type (Value *other) |
void | set_direct (int x, int y, int c, double v) |
void | inc_direct (int x, int y, int c) |
double | get_direct (int x, int y, int c) |
int | width_direct () |
int | height_direct () |
bool | outside (DirectPoint &dp) |
int | channelcount () |
double | horiz () |
double | vertic () |
double | left () |
double | right () |
double | top () |
double | bottom () |
PointValue | topleft () |
PointValue | bottomright () |
double | maxz () |
double | minz () |
double | medianz () |
void | clear (double v) |
void | addFrom (ImageValue *i) |
void | negate () |
QImage | getQImage (bool draw_axes) |
void | drawAxes (QImage *onto) |
void | drawLegend (QPainter *painter, int as, int bs) |
DirectPoint | ocsToDcs (const PointValue &in) |
void | ocsToDcs (const PointValue &in, double &x, double &y) |
PointValue | dcsToOcs (const DirectPoint &in) |
Public Attributes | |
DirectPoint | center |
PointValue | scale |
Protected Member Functions | |
void | loadImage (QString str) |
void | loadImage (QImage &i) |
Private Types | |
typedef Array< 3, float > | Image |
typedef Array< 2, float > | Plane |
typedef Array< 2, float > | ColorLine |
Private Attributes | |
Image | data |
Static Private Attributes | |
static const int | channels = 0 |
static const int | imagex = 1 |
static const int | imagey = 2 |
static const int | colorlinex = 1 |
Definition at line 123 of file image.h.
|
|
|
|
|
|
|
Will create an image with width xs and height ys and c channels. The coordinate system will assume that the pixels are all square and thus xs/ys represents the aspect ratio. Definition at line 28 of file image.cpp. References center, max(), scale, PointValue::x, DirectPoint::x, PointValue::y, and DirectPoint::y. Referenced by deepCopy(). 00028 : data(c,xs,ys) 00029 { 00030 center.x = xs / 2; 00031 center.y = ys / 2; 00032 scale.y = scale.x = max(xs,ys)/2.0; 00033 }
|
|
Initializes an image that will span from topleft to bottomright expressed in orthonormal coordinates at the given resolution Definition at line 51 of file image.cpp. References center, scale, PointValue::x, DirectPoint::x, PointValue::y, and DirectPoint::y. 00052 : data(c,(int)((br.x-tl.x)*res.x),(int)((br.y-tl.y)*res.y)), 00053 scale(res) 00054 { 00055 center.x = (-tl.x)*scale.x; 00056 center.y = (-tl.y)*scale.y; 00057 }
|
|
Initializes the image from the given QImage. The aspect ratio will be preserved. The center placed in the middle and the maximum boundary will be 1 Definition at line 59 of file image.cpp. References loadImage().
|
|
Initializes the image from the image stored in the file pointed to by str. When the image is loaded the aspect ratio will be preserved. The center placed in the middle and the maximum boundary will be 1 Definition at line 64 of file image.cpp. References loadImage().
|
|
Initializes the imagevalue from the data token Definition at line 19 of file image.cpp. References center, data, and scale. 00019 : Value() 00020 { 00021 String filename = desc["filename"]; 00022 QString fn = filename; 00023 data = DataBinner::read_file(fn); 00024 center = DirectPoint(desc["center"]); 00025 scale = PointValue(desc["scale"]); 00026 }
|
|
Will add to the current data the data found in image i relying on the coordinate systems specified in both images. Definition at line 387 of file image.cpp. References bottomright(), channelcount(), dcsToOcs(), get_direct(), ocsToDcs(), outside(), set_direct(), topleft(), DirectPoint::x, and DirectPoint::y. 00388 { 00389 int c1 = channelcount(); 00390 int c2 = i->channelcount(); 00391 if (c1==c2) 00392 { 00393 // printf("Ranging from %g to %g step %g\n",i->left(),i->right(),horiz()); 00394 // we calculate the top left direct coordinate and bottom right direct coordinate 00395 DirectPoint tl = ocsToDcs(i->topleft()); 00396 DirectPoint br = ocsToDcs(i->bottomright()); 00397 DirectPoint cr = tl; 00398 for(cr.x=tl.x; cr.x <= br.x ; cr.x++) 00399 for(cr.y=tl.y ; cr.y <= br.y ; cr.y++) 00400 { 00401 DirectPoint from = i->ocsToDcs(dcsToOcs(cr)); 00402 if (!outside(cr) && !i->outside(from)) 00403 for(int c = 0 ; c < c1 ; c++) 00404 { 00405 double v1 = get_direct(cr.x,cr.y,c); 00406 double v2 = i->get_direct(from.x,from.y,c); 00407 set_direct(cr.x,cr.y,c,v1+v2); 00408 } 00409 } 00410 } 00411 else 00412 assert(0); 00413 }
|
|
return the orthonormal coordinate of the bottom row Definition at line 287 of file image.h. References center, height_direct(), scale, PointValue::y, and DirectPoint::y. Referenced by bottomright(). 00288 { 00289 return ((height_direct()-1)-center.y)/scale.y; 00290 }
|
|
return the bottomright orthnormal coordinate Definition at line 303 of file image.h. References bottom(), and right(). Referenced by Runtime::add(), and addFrom(). 00304 { 00305 return PointValue(right(),bottom()); 00306 }
|
|
returns the number of channels. 3 for color, 1 for gray Definition at line 237 of file image.h. References channels, and data. Referenced by Runtime::add(), addFrom(), Runtime::crop(), deepCopy(), medianz(), and Runtime::straighten().
|
|
sets the entire contents of the image to value v. In multi-channel images all channels are reset. Definition at line 327 of file image.h. References data. Referenced by Runtime::straighten(). 00328 { 00329 data=v; 00330 };
|
|
Convert a pixel coordinate to the matching orthonotmal coordinate. Definition at line 374 of file image.cpp. Referenced by addFrom(), and ImagePicker::pointSelected(). 00375 { 00376 PointValue out=(PointValue)(in-center); 00377 out/=scale; 00378 return out; 00379 }
|
|
Create a deep copy of the image Definition at line 35 of file image.cpp. References center, channelcount(), get_direct(), height_direct(), ImageValue(), scale, set_direct(), and width_direct(). Referenced by Runtime::center(), Runtime::neg(), and Runtime::zoom(). 00036 { 00037 int xs = width_direct(); 00038 int ys = height_direct(); 00039 int cs = channelcount(); 00040 ImageValue * result= new ImageValue(width_direct(),height_direct(),channelcount()); 00041 for(int c = 0 ; c < cs ; c ++) 00042 for(int x = 0 ; x < xs ; x++) 00043 for(int y = 0 ; y < ys ; y++) 00044 result->set_direct(x,y,c, 00045 get_direct(x,y,c)); 00046 result->center = center; 00047 result->scale = scale; 00048 return result; 00049 }
|
|
Will draw the axes on the given painter, assuming that the image is already painted at positoin (0,0) with size sx,sy. Definition at line 202 of file image.cpp. References axe_fatiness(), height_direct(), ocsToDcs(), width_direct(), and DirectPoint::x. 00203 { 00204 int as = onto->width(); 00205 int bs = onto->height(); 00206 int xs = width_direct(); 00207 int ys = height_direct(); 00208 00209 QPen central(Qt::red); 00210 central.setStyle(Qt::SolidLine); 00211 00212 QPen sides(Qt::blue); 00213 sides.setStyle(Qt::SolidLine); 00214 00215 QPen units(Qt::red); 00216 units.setStyle(Qt::DashLine); 00217 00218 double dx,dy; 00219 if (as<100 || bs<100) 00220 { 00221 dx = 1.0; 00222 dy = 1.0; 00223 } 00224 else 00225 { 00226 dx = 0.1; 00227 dy = 0.1; 00228 } 00229 00230 // calculate the size of a pixel in the paintdevice 00231 double pixel_width = (double)as/(double)xs; 00232 double pixel_height = (double)bs/(double)ys; 00233 pixel_width/=2; 00234 pixel_height/=2; 00235 pixel_width+=0.5; 00236 pixel_height+=0.5; 00237 QRgb c; 00238 for(double x = -10.0 ; x <= 10.0 ; x+=dx) 00239 for(double y = -10.0 ; y <= 10.0 ; y+=dy) 00240 { 00241 DirectPoint dp=ocsToDcs(PointValue(x,y)); 00242 // dp refers to the position in the image 00243 int a = pixel_width + dp.x*as/xs; 00244 int b = pixel_height + dp.y*bs/ys; 00245 // a and b now refers to the coordinate in the paintdevice 00246 if (a>=0 && a<as) 00247 { 00248 int s = axe_fatiness(x); 00249 if (s==1) c = qRgb(255,0,0); 00250 else if (s==2) c = qRgb(0,0,255); 00251 else c = qRgb(255,128,128); 00252 00253 for(int y = 0 ; y < bs ; y++) 00254 { 00255 QRgb * scanline = (QRgb*)onto->scanLine(y); 00256 scanline[a]=c; 00257 } 00258 } 00259 00260 if (b>=0 && b<bs) 00261 { 00262 int s = axe_fatiness(y); 00263 if (s==1) c = qRgb(255,0,0); 00264 else if (s==2) c = qRgb(0,0,255); 00265 else c = qRgb(255,128,128); 00266 00267 QRgb * scanline = (QRgb*)onto->scanLine(b); 00268 for(int x = 0 ; x < as ; x++) 00269 scanline[x]=c; 00270 } 00271 } 00272 }
|
|
Paints the legend on the painter Definition at line 274 of file image.cpp. References maxz(), medianz(), and minz(). 00275 { 00276 // now we need to print the extrema 00277 QString hi = QString("max: ")+QString::number(maxz()); 00278 QString lo = QString("min: ")+QString::number(minz()); 00279 QString me = QString("median: ")+QString::number(medianz()); 00280 QString t = hi+"\n"+me+"\n"+lo; 00281 QRect bounds = 00282 painter->boundingRect(0,0,640,480,Qt::AlignBottom|Qt::AlignLeft,t); 00283 if (bounds.width()>as || 00284 bounds.height()>bs/4) return; 00285 painter->setPen(Qt::white); 00286 painter->drawText(2,-2,as,bs,Qt::AlignBottom|Qt::AlignLeft,t); 00287 painter->setPen(Qt::black); 00288 painter->drawText(0,0,as,bs,Qt::AlignBottom|Qt::AlignLeft,t); 00289 }
|
|
Implements Value. Definition at line 75 of file image.cpp. References center, data, Value::equals(), and scale. 00076 { 00077 ImageValue * o = (ImageValue*)other; 00078 return (data == o->data) 00079 && (center == o->center) 00080 && (scale.equals(o->scale)); 00081 };
|
|
Definition at line 202 of file image.h. References data. Referenced by addFrom(), Runtime::crop(), deepCopy(), maxz(), minz(), and Runtime::straighten(). 00203 { 00204 return data[Position<3>(c,x,y)]; 00205 };
|
|
Returns an image that can be further scaled and used for QT visualization. If draw_axes is true then the center and unit lines will be drawn Definition at line 123 of file image.cpp. References channels, colorlinex, data, imagex, imagey, maxz(), minz(), and pos(). Referenced by ImagePicker::ImagePicker(). 00124 { 00125 double loz = minz(); 00126 double hiz = maxz(); 00127 double diz = hiz-loz; 00128 if (diz==0) diz=1; 00129 QImage result(data.size(imagex),data.size(imagey),32); 00130 if (data.size(channels)==1) 00131 for(Image::matrix_positions pos(data,imagey); pos.more() ; ++pos) 00132 { 00133 QRgb * scanline = (QRgb*)result.scanLine(pos[imagey]); 00134 for(ColorLine::ordered_vectors xy(pos,colorlinex); xy.more() ; ++xy, ++scanline) 00135 { 00136 Image::value g = xy; 00137 g-=loz; 00138 g/=diz; 00139 g*=255.0; 00140 *scanline=qRgb((int)g,(int)g,(int)g); 00141 } 00142 } 00143 else 00144 for(Image::matrix_positions y(data,imagey); y.more() ; ++y) 00145 { 00146 QRgb * scanline = (QRgb*)result.scanLine(y[imagey]); 00147 for(ColorLine::ordered_vectors xy(y,colorlinex); xy.more() ; ++xy, ++scanline) 00148 { 00149 Image::vector &c = xy; 00150 float r = c[0]; 00151 float g = c[1]; 00152 float b = c[2]; 00153 00154 r-=loz; 00155 r/=diz; 00156 r*=255.0; 00157 00158 g-=loz; 00159 g/=diz; 00160 g*=255.0; 00161 00162 b-=loz; 00163 b/=diz; 00164 b*=255.0; 00165 00166 int R = (int)r, G = (int)g, B = (int)b; 00167 *scanline=qRgb(R,G,B); 00168 } 00169 } 00170 00171 // draw the axes 00172 /* if (draw_axes) 00173 { 00174 int xs = width_direct(); 00175 int ys = height_direct(); 00176 for(double x = -1.0 ; x <= 1.0 ; x+=0.1) 00177 for(double y = -1.0 ; y <= 1.0 ; y+=0.1) 00178 { 00179 DirectPoint dp=ocsToDcs(PointValue(x,y)); 00180 if (dp.y>=0 && dp.y<ys) 00181 { 00182 QRgb * scanline = (QRgb*)result.scanLine(dp.y); 00183 int delta = axe_fatiness(y); 00184 for(int x = 0 ; x < xs ; x+=delta) scanline[x]=qRgb(0,0,0); 00185 } 00186 if (dp.x>=0 && dp.x<xs) 00187 { 00188 int delta = axe_fatiness(x); 00189 for(int y = 0 ; y < ys ; y+=delta) 00190 { 00191 QRgb * scanline = (QRgb*)result.scanLine(y); 00192 scanline[dp.x]=qRgb(0,0,0); 00193 } 00194 } 00195 } 00196 } 00197 */ 00198 00199 return result; 00200 }
|
|
Will return a description useable to save the data the string is the path where images should be saved to. Implements Value. Definition at line 7 of file image.cpp. References center, data, PointValue::getSaveDescription(), DirectPoint::getSaveDescription(), and scale. 00008 { 00009 QString fn = prefix+"."+QString::number((ulong)(void*)this)+".dat"; 00010 DataBinner::write(data,fn); 00011 Token T; 00012 T["type"]= Symbol("image"); 00013 T["filename"]=String(fn); 00014 T["center"]=center.getSaveDescription(); 00015 T["scale"]=scale.getSaveDescription(prefix); 00016 return T; 00017 };
|
|
returns the number of vertical pixels Definition at line 218 of file image.h. Referenced by bottom(), deepCopy(), drawAxes(), ImagePicker::ImagePicker(), medianz(), outside(), and Runtime::straighten().
|
|
returns the horizontal delta in orthnormal coordinates to reach the next pixel in the underlying storage Definition at line 246 of file image.h. References scale, and PointValue::x.
|
|
Definition at line 198 of file image.h. References data. 00199 { 00200 data[Position<3>(c,x,y)]+=1.0; 00201 };
|
|
return the orthonormal copordinate of the left pixel row Definition at line 263 of file image.h. References center, scale, PointValue::x, and DirectPoint::x. Referenced by topleft().
|
|
When loading an image, the aspect ration is preserved by assigning to both scales the maximum of the width and height. Definition at line 88 of file image.cpp. References center, data, imagex, imagey, max(), pos(), scale, PointValue::x, DirectPoint::x, PointValue::y, and DirectPoint::y. 00089 { 00090 QImage I=I1.convertDepth(32); 00091 bool gray = I.isGrayscale(); 00092 int w = I.width(); 00093 int h = I.height(); 00094 center.x = w / 2; 00095 center.y = h / 2; 00096 scale.y = scale.x = max(w,h)/2.0; 00097 data = Image(gray ? 1 : 3,I.width(),I.height()); 00098 if (gray) 00099 for(Image::positions pos(data); pos.more() ; ++pos) 00100 { 00101 QRgb G = I.pixel(pos[imagex],pos[imagey]); 00102 pos=qGray(G); 00103 } 00104 else 00105 for(Image::vector_positions pos(data,imagex,imagey); pos.more() ; ++pos) 00106 { 00107 QRgb G = I.pixel(pos[imagex],pos[imagey]); 00108 Image::vector & v=pos; 00109 v[0]=qRed(G); 00110 v[1]=qGreen(G); 00111 v[2]=qBlue(G); 00112 } 00113 }
|
|
Definition at line 69 of file image.cpp. Referenced by ImageValue(). 00070 { 00071 QImage i(str); 00072 loadImage(i); 00073 }
|
|
returns the maximum intensity Definition at line 291 of file image.cpp. References get_direct(). Referenced by Runtime::add(), drawLegend(), getQImage(), and Runtime::straighten(). 00292 { 00293 if (data.empty()) return 0; 00294 double mz = get_direct(0,0,0); 00295 for(Image::values v(data); v.more(); ++v) 00296 if (v>mz) mz=v; 00297 return mz; 00298 }
|
|
returns the median intensity Definition at line 320 of file image.cpp. References channelcount(), float_cmp(), height_direct(), and width_direct(). Referenced by drawLegend(). 00321 { 00322 if (data.empty()) return 0; 00323 int size = width_direct()*height_direct()*channelcount(); 00324 float * sort = (float*)malloc(sizeof(float)*size); 00325 assert(sort); 00326 int p = 0; 00327 for(Image::values it(data) ; it.more(); it++) 00328 sort[p++]=*it; 00329 qsort(sort,size,sizeof(float),float_cmp); 00330 float result = sort[size/2]; 00331 free(sort); 00332 return result; 00333 }
|
|
returns the minimum intensity Definition at line 300 of file image.cpp. References get_direct(). Referenced by Runtime::add(), drawLegend(), and getQImage(). 00301 { 00302 if (data.empty()) return 0; 00303 double mz = get_direct(0,0,0); 00304 for(Image::values v(data); v.more(); ++v) 00305 if (v<mz) mz=v; 00306 return mz; 00307 }
|
|
Negate all the values. Definition at line 381 of file image.cpp. Referenced by Runtime::neg(). 00382 { 00383 for(Image::values it(data); it.more() ; it++) 00384 *it = -it; 00385 }
|
|
Helper function to extract the x & y coordinates immediatelly Definition at line 373 of file image.h. References ocsToDcs(), DirectPoint::x, and DirectPoint::y. 00374 { 00375 DirectPoint r = ocsToDcs(in); 00376 x = r.x; 00377 y = r.y; 00378 }
|
|
This function convert the given Orthonormal coordinate to direct pixel coordinates Definition at line 366 of file image.cpp. References center, DirectPoint::copyFrom(), and scale. Referenced by addFrom(), Runtime::center(), Runtime::crop(), drawAxes(), ocsToDcs(), and Runtime::straighten(). 00367 { 00368 DirectPoint out; 00369 out.copyFrom(in * scale); 00370 out+=center; 00371 return out; 00372 }
|
|
returns true if dp is outside the image, false otherwise. Definition at line 226 of file image.h. References height_direct(), width_direct(), DirectPoint::x, and DirectPoint::y. Referenced by addFrom(). 00227 { 00228 return dp.x < 0 || 00229 dp.y < 0 || 00230 dp.x>=width_direct() || 00231 dp.y>=height_direct(); 00232 }
|
|
return the orthonormal copordinate of the right pixel row Definition at line 271 of file image.h. References center, scale, width_direct(), PointValue::x, and DirectPoint::x. Referenced by bottomright(). 00272 { 00273 return ((width_direct()-1)-center.x)/scale.x; 00274 }
|
|
Definition at line 194 of file image.h. References data. Referenced by addFrom(), Runtime::crop(), deepCopy(), and Runtime::straighten(). 00195 { 00196 data[Position<3>(c,x,y)]=v; 00197 };
|
|
return the orthonormal coordinate of the top pixel row Definition at line 279 of file image.h. References center, scale, PointValue::y, and DirectPoint::y. Referenced by topleft().
|
|
return the topleft orthnormal coordinate Definition at line 295 of file image.h. Referenced by Runtime::add(), and addFrom(). 00296 { 00297 return PointValue(left(),top()); 00298 }
|
|
Implements Value. Definition at line 191 of file image.h.
|
|
returns the vertical delta in orthnormal coordinates to reach the next pixel in the underlying storage Definition at line 255 of file image.h. References scale, and PointValue::y.
|
|
returns the number of pixels horizontally Definition at line 210 of file image.h. Referenced by deepCopy(), drawAxes(), ImagePicker::ImagePicker(), medianz(), outside(), right(), and Runtime::straighten().
|
|
The center pixel Definition at line 140 of file image.h. Referenced by bottom(), Runtime::center(), dcsToOcs(), deepCopy(), equals_same_type(), getSaveDescription(), ImageValue(), left(), loadImage(), ocsToDcs(), right(), and top(). |
|
Definition at line 129 of file image.h. Referenced by channelcount(), and getQImage(). |
|
Definition at line 132 of file image.h. Referenced by getQImage(). |
|
Definition at line 128 of file image.h. Referenced by channelcount(), clear(), equals_same_type(), get_direct(), getQImage(), getSaveDescription(), height_direct(), ImageValue(), inc_direct(), loadImage(), set_direct(), and width_direct(). |
|
Definition at line 130 of file image.h. Referenced by getQImage(), loadImage(), and width_direct(). |
|
Definition at line 131 of file image.h. Referenced by getQImage(), height_direct(), and loadImage(). |
|
scale is expressed in pixels per unit (1) Definition at line 145 of file image.h. Referenced by Runtime::add(), bottom(), dcsToOcs(), deepCopy(), equals_same_type(), getSaveDescription(), horiz(), ImageValue(), left(), loadImage(), ocsToDcs(), right(), top(), vertic(), and Runtime::zoom(). |