11 #ifndef KJB_CPP_IMAGE_H
12 #define KJB_CPP_IMAGE_H
15 #include "i/i_matrix.h"
16 #include "i/i_float.h"
17 #include "i/i_float_io.h"
18 #include "i/i_transform.h"
19 #include "i/i_arithmetic.h"
21 #include "i2/i2_draw_text.h"
29 #include <boost/shared_ptr.hpp>
37 #ifdef YES_WE_WANT_GARBAGE_POLICE
86 static const char* BAD_CHANNEL;
89 void sort2(
int& smaller,
int& bigger )
91 if ( smaller > bigger )
97 void compute_row_col(
int index,
int* row,
int* col )
const
104 void compute_row_col_carefully(
int index,
int* row,
int* col )
const
113 compute_row_col( index, row, col );
117 #ifdef YES_WE_WANT_GARBAGE_POLICE
118 mutable std::string info;
119 static int live_object_counter;
120 static int serial_counter;
123 void call_me_in_every_ctor()
125 #ifdef YES_WE_WANT_GARBAGE_POLICE
126 ++live_object_counter;
128 std::ostringstream s;
129 s <<
'(' << serial_counter <<
')';
130 info = s.str() + info;
143 Image(
int rows = 0,
int cols = 0);
146 explicit Image(
const kjb_c::Matrix& src );
154 #ifdef KJB_HAVE_CXX11
174 explicit Image(
const std::string& fname);
182 Image(
int num_rows,
int num_cols,
int r,
int g,
int b);
211 #ifdef YES_WE_WANT_GARBAGE_POLICE
212 fprintf( stderr,
"DTOR: %s\n", info.c_str() );
213 --live_object_counter;
216 kjb_c::kjb_free_image(
m_image);
241 Image&
crop(
int r,
int c,
int num_rows,
int num_cols);
243 #ifdef YES_WE_WANT_GARBAGE_POLICE
244 void infocat(
const std::string& concat_me )
const { info += concat_me; }
246 std::string get_info()
const {
return info; }
247 static int query_live_counter() {
return live_object_counter; }
248 static int query_serial_counter() {
return serial_counter; }
253 void write(
const std::string& fname)
const;
279 #ifdef KJB_HAVE_CXX11
288 kjb_c::kjb_free_image(
m_image );
333 throw std::out_of_range(
"Invalid channel");
353 throw std::out_of_range(
"Invalid channel");
363 return m_image -> pixels[ row ][ col ];
372 return m_image -> pixels[ row ][ col ];
379 compute_row_col( index, &row, &col );
413 float&
at(
int row,
int col,
int channel);
419 float at(
int row,
int col,
int channel)
const;
468 #ifdef YES_WE_WANT_GARBAGE_POLICE
469 fprintf( stderr,
"DTOR: %s\n", info.c_str() );
470 --live_object_counter;
473 kjb_c::kjb_free_image(
m_image);
537 template<
class InputIterator>
588 template <
class Iterator>
596 typedef typename std::iterator_traits<Iterator>::value_type value_type;
599 if(begin == end)
return;
602 Iterator it2 = begin;
604 for(; it2 != end; ++it, ++it2)
691 const std::string& text,
692 const std::string& font_file =
"times14"
705 const std::string& text,
706 const std::string& font_file =
"times14"
729 const kjb_c::KJB_image* overlay,
737 const Image& overlay,
756 int display(
const std::string& title = std::string() )
const;
767 int old_flags =
m_image -> flags;
815 return Image(op1) *= op2;
827 return Image(op1) /= op2;
836 return Image(op1) += op2;
845 return Image(im1) -= im2;
866 return i.
get_flags() & HAS_ALPHA_CHANNEL;
874 template<
class InputIterator>
878 Vector hist(static_cast<int>(256), static_cast<double>(
get_length() / 256.0));
880 for(; first != last; first++)
882 int val =
static_cast<int>(
I(first->first, first->second));
887 hist[val - 1] += 0.15;
892 hist[val + 1] += 0.15;
int draw_text_center(int row, int col, const std::string &text, const std::string &font_file="times14")
Draw the text on the image.
Definition: i_image.cpp:517
boost::shared_ptr< Image > Image_ptr
Definition: i_image.h:776
Definition for the Matrix class, a thin wrapper on the KJB Matrix struct and its related functionalit...
Matrix to_channel_matrix(RGB_channel channel) const
Convert this image to a single matrix by simple averaging of the pixels.
Definition: i_image.cpp:438
void draw_aa_rectangle(int first_row, int first_col, int last_row, int last_col, Pixel_type p)
Draw a solid, axis-aligned rectangle on the image.
Definition: i_image.cpp:186
This class implements matrices, in the linear-algebra sense, restricted to integer-valued elements...
Definition: l_int_matrix.h:71
const Pixel_type & operator()(int row, int col) const
Rvalue pixel access at given row & column, no bounds-checking. The coordinates are row...
Definition: i_image.h:370
Image & operator*=(double op2)
Multiply this image by a scalar; i.e., scale this image in channel space.
Definition: i_image.cpp:164
Vector intensity_histogram(InputIterator first, InputIterator last) const
Computes the intensity histogram of a region – given by a range of pairs – of this image...
Definition: i_image.h:875
bool is_transparency_enabled(const Image &i)
test the Image flag, returning true if the 'alpha' channel is meaningful.
Definition: i_image.h:864
void from_color_matrix(const Int_matrix &m)
Construct an image from a matrix containing RGBA values. Each element of matrix m is an integer which...
Definition: i_image.cpp:272
int display(const std::string &title=std::string()) const
Show the image and return an image number (for closing later).
Definition: i_image.cpp:559
Definition: i_image.h:140
Definition: i_image.h:140
r
Definition: APPgetLargeConnectedEdges.m:127
Image operator-(const Image &im1, const Image &im2)
Subtract two images.
Definition: i_image.h:843
void draw_line_segment(int row_from, int col_from, int row_to, int col_to, int width, Pixel_type p)
Draw a line segment on the image.
Definition: i_image.cpp:473
static Image create_zero_image(int rows, int cols)
Create an empty image of valid zero pixels, r=g=b=0.
Definition: i_image.h:194
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
kjb_c::Pixel Pixel_type
Definition: i_image.h:80
Image scale_image(const Image &i, double factor)
Scale image size by factor, i.e., enlarge or shrink.
Definition: i_image.cpp:603
int get_length() const
Return the number of elements (pixels) in the image.
Definition: i_image.h:268
Image operator+(const Image &op1, const Image &op2)
Add two images.
Definition: i_image.h:834
virtual ~Image()
Dtor simply wraps kjb_free_image()
Definition: i_image.h:209
Impl_type * m_image
Definition: i_image.h:83
static Image create_initialized_image(int rows, int cols, int r, int g, int b)
Create an empty image with pixels initialized to (r, g, b)
Definition: i_image.cpp:86
Image & operator+=(const Image &op2)
Add an image from this image, in place.
Definition: i_image.cpp:146
void draw_circle(int center_row, int center_col, int radius, int line_width, Pixel_type p)
Draw a circle on the image.
Definition: i_image.cpp:495
const Impl_type * c_ptr() const
Access a pointer to the underlying implementation.
Definition: i_image.cpp:419
Pixel_type & operator()(int row, int col)
Lvalue pixel access at given row & column, no bounds-checking. The coordinates are row...
Definition: i_image.h:361
void draw_point(int row, int col, int width, Pixel_type p)
Draw a point on the image.
Definition: i_image.cpp:455
float operator()(int row, int col, int channel) const
Unchecked access of rvalue at given row, column, and RGB_channel.
Definition: i_image.h:342
float & operator()(int row, int col, int channel)
Unchecked access of lvalue at given row, column, and RGB_channel.
Definition: i_image.h:321
for I
Definition: APPgetLargeConnectedEdges.m:141
Impl_type * non_const_c_ptr() const
Access a pointer to the underlying implementation, use with care.
Definition: i_image.h:452
Image & operator/=(double op2)
Divide this image by a scalar; i.e., scale this image in channel space.
Definition: i_image.cpp:176
int draw_text_top_left(int row, int col, const std::string &text, const std::string &font_file="times14")
Draw the text on the image.
Definition: i_image.cpp:528
Image(int rows=0, int cols=0)
Construct image of specified size, defaults to zero by zero.
Definition: i_image.cpp:35
void invert()
Invert this image; i.e., dark becomes light and vice-versa.
Definition: i_image.cpp:312
kjb_c::KJB_image Impl_type
Definition: i_image.h:79
Image & scale(double factor)
Scale the image by factor using imagemagick (deprecated).
Definition: i_image.h:233
int get_num_rows() const
Return the number of rows in the image.
Definition: i_image.h:256
Image get_inverted(const Image &)
Definition: i_image.h:796
Int_matrix to_color_matrix(double scale=1.0) const
Convert this image to a single matrix containing RGBA values. The first eight least significant bits ...
Definition: i_image.cpp:244
int set_flags(int new_flags)
set "flags" field of underlying KJB_image; return previous flags
Definition: i_image.h:765
void set_c_ptr(Impl_type *iimage)
set this matrix to point to a different c memory, freeing the previously pointed area ...
Definition: i_image.h:466
Definition: i_image.h:140
Pixel_type & operator()(int index)
Access lvalue at row-major index, without bounds-checking.
Definition: i_image.h:376
Image operator/(const Image &op1, double op2)
Scale an image in channel space, yielding a new image.
Definition: i_image.h:825
Matrix to_grayscale_matrix(const Image &i)
Definition: i_image.cpp:598
Matrix get_channel(int index) const
Definition: i_image.cpp:317
void draw_disk(int center_row, int center_col, int radius, Pixel_type p)
draw a disk (a filled circle) on the image, of a given color.
Definition: i_image.cpp:506
void draw_arrow(const Vector &src, const Vector &dest, const Image::Pixel_type pixel)
Draw an arrow from src to dest.
Definition: i_image.cpp:570
void swap(kjb::Gsl_Multimin_fdf &m1, kjb::Gsl_Multimin_fdf &m2)
Swap two wrapped multimin objects.
Definition: gsl_multimin.h:693
void draw_image(const kjb_c::KJB_image *overlay, int row=0, int col=0, int scale=1)
Overlay another image on this image, with an optional offset.
Definition: i_image.cpp:539
#define dest(triedge, pointptr)
Definition: triangle.c:938
Image & crop(int r, int c, int num_rows, int num_cols)
Crop this image.
Definition: i_image.cpp:112
int get_num_cols() const
Return the number of columns in the image.
Definition: i_image.h:262
Matrix to_grayscale_matrix() const
Convert this image to a single matrix by simple averaging of the pixels.
Definition: i_image.cpp:424
float & at(int row, int col, int channel)
Access lvalue of pixel channel at row, column coordinates.
Definition: i_image.cpp:351
Image rgb_matrices_to_image(const Matrix &red_channel, const Matrix &green_channel, const Matrix &blue_channel)
Contruct an image from three matrices representing red, green, blue channels.
Definition: i_image.cpp:626
void draw_aa_rectangle_outline(int first_row, int first_col, int last_row, int last_col, Pixel_type p)
Draw the outline of an, axis-aligned rectangle on the image.
Definition: i_image.cpp:224
Image get_inverted() const
Generate an inverted version of this image (deprecated).
Definition: i_image.h:392
void write(const std::string &fname) const
Write to a file.
Definition: i_image.cpp:106
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
void swap(Image &other)
Swap the implementation of two images.
Definition: i_image.h:220
This class implements matrices, in the linear-algebra sense, with real-valued elements.
Definition: m_matrix.h:94
RGB_channel
Constants for accessing color channels via number, with at().
Definition: i_image.h:140
void enable_transparency(Image &i)
set Image flag, to indicate that the 'alpha' channel is meaningful.
Definition: i_image.h:850
for m
Definition: APPgetLargeConnectedEdges.m:64
Wrapped version of the C struct KJB_image.
Definition: i_image.h:76
void from_color_matrices(const Matrix &red, const Matrix &green, const Matrix &blue)
Contruct an image from three matrices representing red, green, blue channels.
Definition: i_image.cpp:445
Image & operator=(const kjb_c::KJB_image &src)
Deep copy assignment from C-type image.
Definition: i_image.cpp:129
void draw_polyline(Iterator begin, Iterator end, int width, Pixel_type p)
Draw a polyline on the image, i.e., a chain of line segments.
Definition: i_image.h:589
Gsl_Vector operator*(double scalar, const Gsl_Vector &vector)
multiply scalar and vector, scalar written on the left side
Definition: gsl_vector.h:661
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
int get_flags() const
return copy of the "flags" field of underlying KJB_image object
Definition: i_image.h:759
void check_bounds(int row, int col) const
Test whether row, column coordinates are valid.
Definition: i_image.cpp:334
friend void swap(kjb::Image &a, kjb::Image &b)
Definition: i_image.h:226
void disable_transparency(Image &i)
clear Image flag, to indicate that the 'alpha' channel is not meaningful.
Definition: i_image.h:857
Definition: i_image.h:140
Image & operator-=(const Image &op2)
Subtract an image from this image, in place.
Definition: i_image.cpp:153