image.h
Go to the documentation of this file.
1 /*******************************************************
2  * Copyright (c) 2014, ArrayFire
3  * All rights reserved.
4  *
5  * This file is distributed under 3-clause BSD license.
6  * The complete license agreement can be obtained at:
7  * http://arrayfire.com/licenses/BSD-3-Clause
8  ********************************************************/
9 
10 #pragma once
11 #include <af/defines.h>
12 #include <af/features.h>
13 
14 #ifdef __cplusplus
15 namespace af
16 {
17 class array;
18 
28 AFAPI void grad(array& dx, array& dy, const array& in);
29 
39 AFAPI array loadImage(const char* filename, const bool is_color=false);
40 
49 AFAPI void saveImage(const char* filename, const array& in);
50 
51 #if AF_API_VERSION >= 31
52 
65 AFAPI array loadImageMem(const void *ptr);
66 #endif
67 
68 #if AF_API_VERSION >= 31
69 
84 AFAPI void* saveImageMem(const array& in, const imageFormat format = AF_FIF_PNG);
85 #endif
86 
87 #if AF_API_VERSION >= 31
88 
96 AFAPI void deleteImageMem(void *ptr);
97 #endif
98 
99 #if AF_API_VERSION >= 32
100 
117 AFAPI array loadImageNative(const char* filename);
118 #endif
119 
120 #if AF_API_VERSION >= 32
121 
147 AFAPI void saveImageNative(const char* filename, const array& in);
148 #endif
149 
161 AFAPI array resize(const array& in, const dim_t odim0, const dim_t odim1, const interpType method=AF_INTERP_NEAREST);
162 
174 AFAPI array resize(const float scale0, const float scale1, const array& in, const interpType method=AF_INTERP_NEAREST);
175 
186 AFAPI array resize(const float scale, const array& in, const interpType method=AF_INTERP_NEAREST);
187 
199 AFAPI array rotate(const array& in, const float theta, const bool crop=true, const interpType method=AF_INTERP_NEAREST);
200 
214 AFAPI array transform(const array& in, const array& transform, const dim_t odim0 = 0, const dim_t odim1 = 0, const interpType method=AF_INTERP_NEAREST, const bool inverse=true);
215 
229 AFAPI array translate(const array& in, const float trans0, const float trans1, const dim_t odim0 = 0, const dim_t odim1 = 0, const interpType method=AF_INTERP_NEAREST);
230 
244 AFAPI array scale(const array& in, const float scale0, const float scale1, const dim_t odim0 = 0, const dim_t odim1 = 0, const interpType method=AF_INTERP_NEAREST);
245 
260 AFAPI array skew(const array& in, const float skew0, const float skew1, const dim_t odim0 = 0, const dim_t odim1 = 0, const bool inverse=true, const interpType method=AF_INTERP_NEAREST);
261 
273 AFAPI array bilateral(const array &in, const float spatial_sigma, const float chromatic_sigma, const bool is_color=false);
274 
288 AFAPI array histogram(const array &in, const unsigned nbins, const double minval, const double maxval);
289 
301 AFAPI array histogram(const array &in, const unsigned nbins);
302 
315 AFAPI array meanShift(const array& in, const float spatial_sigma, const float chromatic_sigma, const unsigned iter, const bool is_color=false);
316 
331 AFAPI array medfilt(const array& in, const dim_t wind_length = 3, const dim_t wind_width = 3, const borderType edge_pad = AF_PAD_ZERO);
332 
345 AFAPI array minfilt(const array& in, const dim_t wind_length = 3, const dim_t wind_width = 3, const borderType edge_pad = AF_PAD_ZERO);
346 
359 AFAPI array maxfilt(const array& in, const dim_t wind_length = 3, const dim_t wind_width = 3, const borderType edge_pad = AF_PAD_ZERO);
360 
372 AFAPI array dilate(const array& in, const array& mask);
373 
383 AFAPI array dilate3(const array& in, const array& mask);
384 
396 AFAPI array erode(const array& in, const array& mask);
397 
407 AFAPI array erode3(const array& in, const array& mask);
408 
437 
450 AFAPI void sobel(array &dx, array &dy, const array &img, const unsigned ker_size=3);
451 
464 AFAPI array sobel(const array &img, const unsigned ker_size=3, const bool isFast=false);
465 
479 AFAPI array rgb2gray(const array& in, const float rPercent=0.2126f, const float gPercent=0.7152f, const float bPercent=0.0722f);
480 
494 AFAPI array gray2rgb(const array& in, const float rFactor=1.0, const float gFactor=1.0, const float bFactor=1.0);
495 
509 AFAPI array histEqual(const array& in, const array& hist);
510 
522 AFAPI array gaussianKernel(const int rows, const int cols, const double sig_r = 0, const double sig_c = 0);
523 
534 AFAPI array hsv2rgb(const array& in);
535 
546 AFAPI array rgb2hsv(const array& in);
547 
562 AFAPI array colorSpace(const array& image, const CSpace to, const CSpace from);
563 
564 #if AF_API_VERSION >= 31
565 
580 AFAPI array unwrap(const array& in, const dim_t wx, const dim_t wy,
581  const dim_t sx, const dim_t sy, const dim_t px=0, const dim_t py=0,
582  const bool is_column = true);
583 #endif
584 
585 #if AF_API_VERSION >= 31
586 
603 AFAPI array wrap(const array& in,
604  const dim_t ox, const dim_t oy,
605  const dim_t wx, const dim_t wy,
606  const dim_t sx, const dim_t sy,
607  const dim_t px = 0, const dim_t py = 0,
608  const bool is_column = true);
609 #endif
610 
611 #if AF_API_VERSION >= 31
612 
620 AFAPI array sat(const array& in);
621 #endif
622 
623 #if AF_API_VERSION >= 31
624 
636 AFAPI array ycbcr2rgb(const array& in, const YCCStd standard=AF_YCC_601);
637 #endif
638 
639 #if AF_API_VERSION >= 31
640 
652 AFAPI array rgb2ycbcr(const array& in, const YCCStd standard=AF_YCC_601);
653 #endif
654 
655 }
656 #endif
657 
658 #ifdef __cplusplus
659 extern "C" {
660 #endif
661 
673  AFAPI af_err af_gradient(af_array *dx, af_array *dy, const af_array in);
674 
686  AFAPI af_err af_load_image(af_array *out, const char* filename, const bool isColor);
687 
698  AFAPI af_err af_save_image(const char* filename, const af_array in);
699 
700 #if AF_API_VERSION >= 31
701 
711  AFAPI af_err af_load_image_memory(af_array *out, const void* ptr);
712 #endif
713 
714 #if AF_API_VERSION >= 31
715 
727  AFAPI af_err af_save_image_memory(void** ptr, const af_array in, const af_image_format format);
728 #endif
729 
730 #if AF_API_VERSION >= 31
731 
741 #endif
742 
743 #if AF_API_VERSION >= 32
744 
762  AFAPI af_err af_load_image_native(af_array *out, const char* filename);
763 #endif
764 
765 #if AF_API_VERSION >= 32
766 
794  AFAPI af_err af_save_image_native(const char* filename, const af_array in);
795 #endif
796 
811  AFAPI af_err af_resize(af_array *out, const af_array in, const dim_t odim0, const dim_t odim1, const af_interp_type method);
812 
829  const dim_t odim0, const dim_t odim1,
830  const af_interp_type method, const bool inverse);
831 
845  AFAPI af_err af_rotate(af_array *out, const af_array in, const float theta,
846  const bool crop, const af_interp_type method);
862  AFAPI af_err af_translate(af_array *out, const af_array in, const float trans0, const float trans1,
863  const dim_t odim0, const dim_t odim1, const af_interp_type method);
879  AFAPI af_err af_scale(af_array *out, const af_array in, const float scale0, const float scale1,
880  const dim_t odim0, const dim_t odim1, const af_interp_type method);
897  AFAPI af_err af_skew(af_array *out, const af_array in, const float skew0, const float skew1,
898  const dim_t odim0, const dim_t odim1, const af_interp_type method,
899  const bool inverse);
900 
914  AFAPI af_err af_histogram(af_array *out, const af_array in, const unsigned nbins, const double minval, const double maxval);
915 
929  AFAPI af_err af_dilate(af_array *out, const af_array in, const af_array mask);
930 
942  AFAPI af_err af_dilate3(af_array *out, const af_array in, const af_array mask);
943 
957  AFAPI af_err af_erode(af_array *out, const af_array in, const af_array mask);
958 
970  AFAPI af_err af_erode3(af_array *out, const af_array in, const af_array mask);
971 
985  AFAPI af_err af_bilateral(af_array *out, const af_array in, const float spatial_sigma, const float chromatic_sigma, const bool isColor);
986 
1001  AFAPI af_err af_mean_shift(af_array *out, const af_array in, const float spatial_sigma, const float chromatic_sigma, const unsigned iter, const bool is_color);
1002 
1017  AFAPI af_err af_medfilt(af_array *out, const af_array in, const dim_t wind_length, const dim_t wind_width, const af_border_type edge_pad);
1018 
1033  AFAPI af_err af_minfilt(af_array *out, const af_array in, const dim_t wind_length, const dim_t wind_width, const af_border_type edge_pad);
1034 
1049  AFAPI af_err af_maxfilt(af_array *out, const af_array in, const dim_t wind_length, const dim_t wind_width, const af_border_type edge_pad);
1050 
1063  AFAPI af_err af_regions(af_array *out, const af_array in, const af_connectivity connectivity, const af_dtype ty);
1064 
1079  AFAPI af_err af_sobel_operator(af_array *dx, af_array *dy, const af_array img, const unsigned ker_size);
1080 
1096  AFAPI af_err af_rgb2gray(af_array* out, const af_array in, const float rPercent, const float gPercent, const float bPercent);
1097 
1113  AFAPI af_err af_gray2rgb(af_array* out, const af_array in, const float rFactor, const float gFactor, const float bFactor);
1114 
1128  AFAPI af_err af_hist_equal(af_array *out, const af_array in, const af_array hist);
1129 
1144  const int rows, const int cols,
1145  const double sigma_r, const double sigma_c);
1146 
1159  AFAPI af_err af_hsv2rgb(af_array* out, const af_array in);
1160 
1173  AFAPI af_err af_rgb2hsv(af_array* out, const af_array in);
1174 
1192  AFAPI af_err af_color_space(af_array *out, const af_array image, const af_cspace_t to, const af_cspace_t from);
1193 
1194 #if AF_API_VERSION >= 31
1195 
1212  AFAPI af_err af_unwrap(af_array *out, const af_array in, const dim_t wx, const dim_t wy,
1213  const dim_t sx, const dim_t sy, const dim_t px, const dim_t py,
1214  const bool is_column);
1215 #endif
1216 
1217 #if AF_API_VERSION >= 31
1218 
1240  const af_array in,
1241  const dim_t ox, const dim_t oy,
1242  const dim_t wx, const dim_t wy,
1243  const dim_t sx, const dim_t sy,
1244  const dim_t px, const dim_t py,
1245  const bool is_column);
1246 #endif
1247 
1248 #if AF_API_VERSION >= 31
1249 
1259  AFAPI af_err af_sat(af_array *out, const af_array in);
1260 #endif
1261 
1262 #if AF_API_VERSION >= 31
1263 
1277  AFAPI af_err af_ycbcr2rgb(af_array* out, const af_array in, const af_ycc_std standard);
1278 #endif
1279 
1280 #if AF_API_VERSION >= 31
1281 
1295  AFAPI af_err af_rgb2ycbcr(af_array* out, const af_array in, const af_ycc_std standard);
1296 #endif
1297 #ifdef __cplusplus
1298 }
1299 #endif
AFAPI array scale(const array &in, const float scale0, const float scale1, const dim_t odim0=0, const dim_t odim1=0, const interpType method=AF_INTERP_NEAREST)
C++ Interface for scaling an image.
AFAPI void saveImage(const char *filename, const array &in)
C++ Interface for saving an image.
AFAPI af_err af_load_image(af_array *out, const char *filename, const bool isColor)
C Interface for loading an image.
AFAPI af_err af_dilate(af_array *out, const af_array in, const af_array mask)
C Interface for image dilation (max filter)
af_ycc_std
Definition: defines.h:285
AFAPI af_err af_maxfilt(af_array *out, const af_array in, const dim_t wind_length, const dim_t wind_width, const af_border_type edge_pad)
C Interface for maximum filter.
AFAPI af_err af_dilate3(af_array *out, const af_array in, const af_array mask)
C Interface for 3d image dilation.
AFAPI array minfilt(const array &in, const dim_t wind_length=3, const dim_t wind_width=3, const borderType edge_pad=AF_PAD_ZERO)
C++ Interface for minimum filter.
Definition: algorithm.h:14
AFAPI void deleteImageMem(void *ptr)
C++ Interface for deleting memory created by saveImageMem or af_save_image_memory.
AFAPI af_err af_transform(af_array *out, const af_array in, const af_array transform, const dim_t odim0, const dim_t odim1, const af_interp_type method, const bool inverse)
C Interface for transforming an image.
AFAPI af_err af_gaussian_kernel(af_array *out, const int rows, const int cols, const double sigma_r, const double sigma_c)
C Interface generating gaussian kernels.
AFAPI array ycbcr2rgb(const array &in, const YCCStd standard=AF_YCC_601)
C++ Interface for converting YCbCr to RGB.
AFAPI af_err af_unwrap(af_array *out, const af_array in, const dim_t wx, const dim_t wy, const dim_t sx, const dim_t sy, const dim_t px, const dim_t py, const bool is_column)
C Interface wrapper for unwrap.
AFAPI array rgb2gray(const array &in, const float rPercent=0.2126f, const float gPercent=0.7152f, const float bPercent=0.0722f)
C++ Interface for RGB to gray conversion.
af_border_type
Definition: defines.h:229
AFAPI array rotate(const array &in, const float theta, const bool crop=true, const interpType method=AF_INTERP_NEAREST)
C++ Interface for rotating an image.
AFAPI af_err af_scale(af_array *out, const af_array in, const float scale0, const float scale1, const dim_t odim0, const dim_t odim1, const af_interp_type method)
C Interface for scaling an image.
AFAPI af_err af_load_image_memory(af_array *out, const void *ptr)
C Interface for loading an image from memory.
AFAPI array hsv2rgb(const array &in)
C++ Interface for converting HSV to RGB.
AFAPI af_err af_load_image_native(af_array *out, const char *filename)
C Interface for loading an image as is original type.
AFAPI af_err af_histogram(af_array *out, const af_array in, const unsigned nbins, const double minval, const double maxval)
C Interface for histogram.
AFAPI array histogram(const array &in, const unsigned nbins, const double minval, const double maxval)
C++ Interface for histogram.
AFAPI af_err af_erode3(af_array *out, const af_array in, const af_array mask)
C Interface for 3D image erosion.
af_ycc_std YCCStd
Definition: defines.h:399
AFAPI af_err af_medfilt(af_array *out, const af_array in, const dim_t wind_length, const dim_t wind_width, const af_border_type edge_pad)
C Interface for median filter.
AFAPI array meanShift(const array &in, const float spatial_sigma, const float chromatic_sigma, const unsigned iter, const bool is_color=false)
C++ Interface for mean shift.
AFAPI array histEqual(const array &in, const array &hist)
C++ Interface for histogram equalization.
AFAPI af_err af_wrap(af_array *out, const af_array in, const dim_t ox, const dim_t oy, const dim_t wx, const dim_t wy, const dim_t sx, const dim_t sy, const dim_t px, const dim_t py, const bool is_column)
C Interface wrapper for wrap.
AFAPI array wrap(const array &in, const dim_t ox, const dim_t oy, const dim_t wx, const dim_t wy, const dim_t sx, const dim_t sy, const dim_t px=0, const dim_t py=0, const bool is_column=true)
C++ Interface wrapper for wrap.
AFAPI af_err af_gray2rgb(af_array *out, const af_array in, const float rFactor, const float gFactor, const float bFactor)
C Interface for converting gray to RGB.
AFAPI array regions(const array &in, const af::connectivity connectivity=AF_CONNECTIVITY_4, const dtype type=f32)
C++ Interface for getting regions in an image.
af_interp_type
Definition: defines.h:221
AFAPI af_err af_regions(af_array *out, const af_array in, const af_connectivity connectivity, const af_dtype ty)
C Interface for regions in an image.
AFAPI af_err af_save_image_native(const char *filename, const af_array in)
C Interface for saving an image without modifications.
AFAPI af_err af_minfilt(af_array *out, const af_array in, const dim_t wind_length, const dim_t wind_width, const af_border_type edge_pad)
C Interface for minimum filter.
AFAPI void sobel(array &dx, array &dy, const array &img, const unsigned ker_size=3)
C++ Interface for extracting sobel gradients.
AFAPI af_err af_delete_image_memory(void *ptr)
C Interface for deleting an image from memory.
af_image_format imageFormat
Definition: defines.h:402
AFAPI array inverse(const array &in, const matProp options=AF_MAT_NONE)
C++ Interface for inverting a matrix.
AFAPI array erode(const array &in, const array &mask)
C++ Interface for image erosion (min filter)
AFAPI af_err af_hsv2rgb(af_array *out, const af_array in)
C Interface for converting HSV to RGB.
AFAPI af_err af_save_image(const char *filename, const af_array in)
C Interface for saving an image.
af_connectivity
Definition: defines.h:241
AFAPI array dilate3(const array &in, const array &mask)
C++ Interface for 3D image dilation.
af_err
Definition: defines.h:67
Connectivity includes neighbors, North, East, South and West of current pixel.
Definition: defines.h:245
AFAPI af_err af_rgb2hsv(af_array *out, const af_array in)
C Interface for converting RGB to HSV.
AFAPI array transform(const array &in, const array &transform, const dim_t odim0=0, const dim_t odim1=0, const interpType method=AF_INTERP_NEAREST, const bool inverse=true)
C++ Interface for transforming an image.
AFAPI array gaussianKernel(const int rows, const int cols, const double sig_r=0, const double sig_c=0)
C++ Interface for generating gausian kernels.
AFAPI void saveImageNative(const char *filename, const array &in)
C++ Interface for saving an image without modifications.
ITU-R BT.601 (formerly CCIR 601) standard.
Definition: defines.h:286
AFAPI af_err af_bilateral(af_array *out, const af_array in, const float spatial_sigma, const float chromatic_sigma, const bool isColor)
C Interface for bilateral filter.
AFAPI af_err af_rotate(af_array *out, const af_array in, const float theta, const bool crop, const af_interp_type method)
C Interface for rotating an image.
AFAPI void grad(array &dx, array &dy, const array &in)
C++ Interface for calculating the gradients.
Out of bound values are 0.
Definition: defines.h:233
AFAPI af_err af_hist_equal(af_array *out, const af_array in, const af_array hist)
C Interface for histogram equalization.
AFAPI af_err af_sat(af_array *out, const af_array in)
C Interface wrapper for summed area tables.
AFAPI af_err af_rgb2gray(af_array *out, const af_array in, const float rPercent, const float gPercent, const float bPercent)
C Interface for converting RGB to gray.
AFAPI af_err af_gradient(af_array *dx, af_array *dy, const af_array in)
C Interface for calculating the gradients.
long long dim_t
Definition: defines.h:50
AFAPI array resize(const array &in, const dim_t odim0, const dim_t odim1, const interpType method=AF_INTERP_NEAREST)
C++ Interface for resizing an image to specified dimensions.
AFAPI array rgb2hsv(const array &in)
C++ Interface for converting RGB to HSV.
AFAPI array dilate(const array &in, const array &mask)
C++ Interface for image dilation (max filter)
AFAPI array skew(const array &in, const float skew0, const float skew1, const dim_t odim0=0, const dim_t odim1=0, const bool inverse=true, const interpType method=AF_INTERP_NEAREST)
C++ Interface for skewing an image.
AFAPI af_err af_resize(af_array *out, const af_array in, const dim_t odim0, const dim_t odim1, const af_interp_type method)
C Interface for resizing an image to specified dimensions.
AFAPI array rgb2ycbcr(const array &in, const YCCStd standard=AF_YCC_601)
C++ Interface for converting RGB to YCbCr.
#define AFAPI
Definition: defines.h:31
af_border_type borderType
Definition: defines.h:387
AFAPI af_err af_translate(af_array *out, const af_array in, const float trans0, const float trans1, const dim_t odim0, const dim_t odim1, const af_interp_type method)
C Interface for translate an image.
AFAPI array loadImageNative(const char *filename)
C++ Interface for loading an image as its original type.
AFAPI array maxfilt(const array &in, const dim_t wind_length=3, const dim_t wind_width=3, const borderType edge_pad=AF_PAD_ZERO)
C++ Interface for maximum filter.
AFAPI array loadImage(const char *filename, const bool is_color=false)
C++ Interface for loading an image.
static af::array array(af::dim4 idims, cl_mem buf, af::dtype type, bool retain=false)
Create an af::array object from an OpenCL cl_mem buffer.
Definition: opencl.h:161
AFAPI array bilateral(const array &in, const float spatial_sigma, const float chromatic_sigma, const bool is_color=false)
C++ Interface for bilateral filter.
AFAPI array medfilt(const array &in, const dim_t wind_length=3, const dim_t wind_width=3, const borderType edge_pad=AF_PAD_ZERO)
C++ Interface for median filter.
Nearest Interpolation.
Definition: defines.h:222
AFAPI af_err af_erode(af_array *out, const af_array in, const af_array mask)
C Interface for image erosion (min filter)
AFAPI array sat(const array &in)
C++ Interface wrapper for summed area tables.
af_cspace_t
Definition: defines.h:292
FreeImage Enum for Portable Network Graphics File.
Definition: defines.h:345
void * af_array
Definition: defines.h:219
AFAPI array colorSpace(const array &image, const CSpace to, const CSpace from)
C++ Interface wrapper for colorspace conversion.
af_image_format
Definition: defines.h:340
af_cspace_t CSpace
Definition: defines.h:390
32-bit floating point values
Definition: defines.h:193
AFAPI af_err af_rgb2ycbcr(af_array *out, const af_array in, const af_ycc_std standard)
C Interface for converting RGB to YCbCr.
AFAPI af_err af_save_image_memory(void **ptr, const af_array in, const af_image_format format)
C Interface for saving an image to memory using FreeImage.
AFAPI void * saveImageMem(const array &in, const imageFormat format=AF_FIF_PNG)
C++ Interface for saving an image to memory.
AFAPI array erode3(const array &in, const array &mask)
C++ Interface for 3d for image erosion.
af_dtype
Definition: defines.h:192
af_interp_type interpType
Definition: defines.h:386
AFAPI af_err af_color_space(af_array *out, const af_array image, const af_cspace_t to, const af_cspace_t from)
C Interface wrapper for color space conversion.
af_dtype dtype
Definition: defines.h:384
AFAPI array translate(const array &in, const float trans0, const float trans1, const dim_t odim0=0, const dim_t odim1=0, const interpType method=AF_INTERP_NEAREST)
C++ Interface for translating an image.
AFAPI array gray2rgb(const array &in, const float rFactor=1.0, const float gFactor=1.0, const float bFactor=1.0)
C++ Interface for gray to RGB conversion.
AFAPI array loadImageMem(const void *ptr)
C++ Interface for loading an image from memory.
AFAPI af_err af_mean_shift(af_array *out, const af_array in, const float spatial_sigma, const float chromatic_sigma, const unsigned iter, const bool is_color)
C Interface for mean shift.
AFAPI af_err af_sobel_operator(af_array *dx, af_array *dy, const af_array img, const unsigned ker_size)
C Interface for getting sobel gradients.
AFAPI array unwrap(const array &in, const dim_t wx, const dim_t wy, const dim_t sx, const dim_t sy, const dim_t px=0, const dim_t py=0, const bool is_column=true)
C++ Interface wrapper for unwrap.
AFAPI af_err af_ycbcr2rgb(af_array *out, const af_array in, const af_ycc_std standard)
C Interface for converting YCbCr to RGB.
af_connectivity connectivity
Definition: defines.h:388
AFAPI af_err af_skew(af_array *out, const af_array in, const float skew0, const float skew1, const dim_t odim0, const dim_t odim1, const af_interp_type method, const bool inverse)
C Interface for skewing an image.