[GRASS-SVN] r52501 - grass-addons/grass7/imagery/i.edge
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Aug 2 05:10:56 PDT 2012
Author: wenzeslaus
Date: 2012-08-02 05:10:56 -0700 (Thu, 02 Aug 2012)
New Revision: 52501
Modified:
grass-addons/grass7/imagery/i.edge/canny.c
grass-addons/grass7/imagery/i.edge/canny.h
grass-addons/grass7/imagery/i.edge/gauss.c
grass-addons/grass7/imagery/i.edge/gauss.h
grass-addons/grass7/imagery/i.edge/i.edge.html
grass-addons/grass7/imagery/i.edge/main.c
Log:
i.edge: changing DCELL to CELL
Modified: grass-addons/grass7/imagery/i.edge/canny.c
===================================================================
--- grass-addons/grass7/imagery/i.edge/canny.c 2012-08-02 11:27:51 UTC (rev 52500)
+++ grass-addons/grass7/imagery/i.edge/canny.c 2012-08-02 12:10:56 UTC (rev 52501)
@@ -50,19 +50,19 @@
int initY = cols * (kernelWidth - 1);
- int maxY = cols * (rows - (kernelWidth - 1));
+ size_t maxY = (size_t) cols * (rows - (kernelWidth - 1));
int x;
- int y;
+ size_t y;
int i;
for (x = initX; x < maxX; x++) {
for (y = initY; y < maxY; y += cols) {
- float sum = 0.;
+ double sum = 0.;
- int index = x + y;
+ size_t index = x + y;
for (i = 1; i < kernelWidth; i++) {
sum += diffKernel[i] * (yConv[index - i] - yConv[index + i]);
@@ -78,19 +78,19 @@
{
int initY = cols * (kernelWidth - 1);
- int maxY = cols * (rows - (kernelWidth - 1));
+ size_t maxY = (size_t) cols * (rows - (kernelWidth - 1));
int x;
- int y;
+ size_t y;
int i;
for (x = kernelWidth; x < cols - kernelWidth; x++) {
for (y = initY; y < maxY; y += cols) {
- float sum = 0.0;
+ double sum = 0.0;
- int index = x + y;
+ size_t index = x + y;
int yOffset = cols;
@@ -105,9 +105,9 @@
}
}
-static float custom_hypot(float x, float y)
+static double custom_hypot(double x, double y)
{
- float t;
+ double t;
x = fabs(x);
y = fabs(y);
@@ -153,11 +153,11 @@
* variable (3) and reused in the mirror case (4).
*
*/
-static int isLocalMax(float xGrad, float yGrad, float gradMag,
- float neMag, float seMag, float swMag, float nwMag,
- float nMag, float eMag, float sMag, float wMag)
+static int isLocalMax(double xGrad, double yGrad, double gradMag,
+ double neMag, double seMag, double swMag, double nwMag,
+ double nMag, double eMag, double sMag, double wMag)
{
- float tmp, tmp1, tmp2;
+ double tmp, tmp1, tmp2;
if (xGrad * yGrad <= 0.0f) {
if (fabs(xGrad) >= fabs(yGrad)) {
@@ -189,10 +189,10 @@
return 0;
}
-void nonmaxSuppresion(DCELL * xGradient, DCELL * yGradient, DCELL * magnitude,
- DCELL * angle,
+void nonmaxSuppresion(DCELL * xGradient, DCELL * yGradient, CELL * magnitude,
+ CELL *angle,
int rows, int cols, int kernelWidth,
- float magnitudeScale, float magnitudeLimit)
+ int magnitudeScale, int magnitudeLimit)
{
int initX = kernelWidth;
@@ -200,17 +200,17 @@
int initY = cols * kernelWidth;
- int maxY = cols * (rows - kernelWidth);
+ size_t maxY = cols * (rows - kernelWidth);
int x;
- int y;
+ size_t y;
int MAGNITUDE_MAX = magnitudeScale * magnitudeLimit;
for (x = initX; x < maxX; x++) {
for (y = initY; y < maxY; y += cols) {
- int index = x + y;
+ size_t index = x + y;
int indexN = index - cols;
@@ -228,31 +228,31 @@
int indexSE = indexS + 1;
- float xGrad = xGradient[index];
+ double xGrad = xGradient[index];
- float yGrad = yGradient[index];
+ double yGrad = yGradient[index];
- float gradMag = custom_hypot(xGrad, yGrad);
+ double gradMag = custom_hypot(xGrad, yGrad);
/* perform non-maximal supression */
- float nMag = custom_hypot(xGradient[indexN], yGradient[indexN]);
+ double nMag = custom_hypot(xGradient[indexN], yGradient[indexN]);
- float sMag = custom_hypot(xGradient[indexS], yGradient[indexS]);
+ double sMag = custom_hypot(xGradient[indexS], yGradient[indexS]);
- float wMag = custom_hypot(xGradient[indexW], yGradient[indexW]);
+ double wMag = custom_hypot(xGradient[indexW], yGradient[indexW]);
- float eMag = custom_hypot(xGradient[indexE], yGradient[indexE]);
+ double eMag = custom_hypot(xGradient[indexE], yGradient[indexE]);
- float neMag =
+ double neMag =
custom_hypot(xGradient[indexNE], yGradient[indexNE]);
- float seMag =
+ double seMag =
custom_hypot(xGradient[indexSE], yGradient[indexSE]);
- float swMag =
+ double swMag =
custom_hypot(xGradient[indexSW], yGradient[indexSW]);
- float nwMag =
+ double nwMag =
custom_hypot(xGradient[indexNW], yGradient[indexNW]);
if (isLocalMax(xGrad, yGrad, gradMag, neMag, seMag, swMag, nwMag,
@@ -260,7 +260,7 @@
magnitude[index] =
gradMag >=
magnitudeLimit ? MAGNITUDE_MAX : (int)(magnitudeScale *
- gradMag);
+ gradMag + 0.5);
/*
NOTE: The orientation of the edge is not employed by this
implementation. It is a simple matter to compute it at
@@ -268,7 +268,7 @@
*/
if (angle != NULL)
{
- angle[index] = atan2(yGrad, xGrad) * 180 / M_PI;;
+ angle[index] = (int) (atan2(yGrad, xGrad) * 180 / M_PI + 0.5);
}
}
else {
@@ -278,7 +278,7 @@
}
}
-static void follow(DCELL * edges, DCELL * magnitude, int x1, int y1, int i1,
+static void follow(CELL * edges, CELL * magnitude, int x1, int y1, int i1,
int threshold, int rows, int cols)
{
int x0 = x1 == 0 ? x1 : x1 - 1;
@@ -308,7 +308,7 @@
}
/* edges.fill(0) */
-void performHysteresis(DCELL * edges, DCELL * magnitude, int low, int high,
+void performHysteresis(CELL * edges, CELL * magnitude, int low, int high,
int rows, int cols)
{
/*
@@ -334,11 +334,12 @@
}
}
-void thresholdEdges(DCELL * edges, int rows, int cols)
+void thresholdEdges(CELL * edges, int rows, int cols)
{
int i;
+ size_t max = (size_t) rows * cols;
- for (i = 0; i < rows * cols; i++) {
+ for (i = 0; i < max; i++) {
edges[i] = edges[i] > 0 ? 1 : 0;
}
}
Modified: grass-addons/grass7/imagery/i.edge/canny.h
===================================================================
--- grass-addons/grass7/imagery/i.edge/canny.h 2012-08-02 11:27:51 UTC (rev 52500)
+++ grass-addons/grass7/imagery/i.edge/canny.h 2012-08-02 12:10:56 UTC (rev 52501)
@@ -9,13 +9,13 @@
void computeYGradients(DCELL * diffKernel, DCELL * xConv, DCELL * yGradient,
int rows, int cols, int kernelWidth);
-void nonmaxSuppresion(DCELL * xGradient, DCELL * yGradient, DCELL * magnitude,
- DCELL *angle, int rows, int cols,
- int kernelWidth, float magnitudeScale, float magnitudeLimit);
+void nonmaxSuppresion(DCELL * xGradient, DCELL * yGradient, CELL *magnitude,
+ CELL *angle, int rows, int cols,
+ int kernelWidth, int magnitudeScale, int magnitudeLimit);
-void performHysteresis(DCELL * edges, DCELL * magnitude,
+void performHysteresis(CELL * edges, CELL *magnitude,
int low, int high, int rows, int cols);
-void thresholdEdges(DCELL * edges, int rows, int cols);
+void thresholdEdges(CELL * edges, int rows, int cols);
#endif /* CANNY_H */
Modified: grass-addons/grass7/imagery/i.edge/gauss.c
===================================================================
--- grass-addons/grass7/imagery/i.edge/gauss.c 2012-08-02 11:27:51 UTC (rev 52500)
+++ grass-addons/grass7/imagery/i.edge/gauss.c 2012-08-02 12:10:56 UTC (rev 52501)
@@ -4,31 +4,31 @@
#include <grass/gis.h>
-int getKernelWidth(const float sigma, float gaussianCutOff)
+int getKernelWidth(const double sigma, double gaussianCutOff)
{
- return ceil(sqrt(-2 * sigma * sigma * log(gaussianCutOff)));
+ return (int) ceil(sqrt(-2 * sigma * sigma * log(gaussianCutOff)));
}
-static float gaussian(float x, float sigma)
+static double gaussian(double x, double sigma)
{
return exp(-(x * x) / (2.0 * sigma * sigma));
}
void gaussKernel(DCELL * gaussKernel, DCELL * diffKernel,
- int kernelWidth, float kernelRadius)
+ int kernelWidth, double kernelRadius)
{
int kwidth;
for (kwidth = 0; kwidth < kernelWidth; kwidth++) {
- float g1 = gaussian(kwidth, kernelRadius);
+ double g1 = gaussian(kwidth, kernelRadius);
- float g2 = gaussian(kwidth - 0.5, kernelRadius);
+ double g2 = gaussian(kwidth - 0.5, kernelRadius);
- float g3 = gaussian(kwidth + 0.5, kernelRadius);
+ double g3 = gaussian(kwidth + 0.5, kernelRadius);
gaussKernel[kwidth] =
(g1 + g2 +
- g3) / 3. / (2.0 * (float)M_PI * kernelRadius * kernelRadius);
+ g3) / 3. / (2.0 * (double)M_PI * kernelRadius * kernelRadius);
diffKernel[kwidth] = g3 - g2;
}
}
@@ -36,7 +36,8 @@
void gaussConvolution(DCELL * image, DCELL * kernel, DCELL * xConv,
DCELL * yConv, int rows, int cols, int kernelWidth)
{
- int x, y;
+ int x;
+ size_t y;
int initX = kernelWidth - 1;
@@ -44,16 +45,16 @@
int initY = cols * (kernelWidth - 1);
- int maxY = cols * (rows - (kernelWidth - 1));
+ size_t maxY = (size_t) cols * (rows - (kernelWidth - 1));
//perform convolution in x and y directions
for (x = initX; x < maxX; x++) {
for (y = initY; y < maxY; y += cols) {
- int index = x + y;
+ size_t index = x + y;
- float sumX = image[index] * kernel[0];
+ double sumX = image[index] * kernel[0];
- float sumY = sumX;
+ double sumY = sumX;
int xOffset = 1;
Modified: grass-addons/grass7/imagery/i.edge/gauss.h
===================================================================
--- grass-addons/grass7/imagery/i.edge/gauss.h 2012-08-02 11:27:51 UTC (rev 52500)
+++ grass-addons/grass7/imagery/i.edge/gauss.h 2012-08-02 12:10:56 UTC (rev 52501)
@@ -3,10 +3,10 @@
#include <grass/gis.h>
-int getKernelWidth(const float sigma, float gaussianCutOff);
+int getKernelWidth(const double sigma, double gaussianCutOff);
void gaussKernel(DCELL * gaussKernel, DCELL * diffKernel,
- int kernelWidth, float kernelRadius);
+ int kernelWidth, double kernelRadius);
void gaussConvolution(DCELL * image, DCELL * kernel, DCELL * xConv,
DCELL * yConv, int rows, int cols, int kernelWidth);
Modified: grass-addons/grass7/imagery/i.edge/i.edge.html
===================================================================
--- grass-addons/grass7/imagery/i.edge/i.edge.html 2012-08-02 11:27:51 UTC (rev 52500)
+++ grass-addons/grass7/imagery/i.edge/i.edge.html 2012-08-02 12:10:56 UTC (rev 52501)
@@ -15,3 +15,4 @@
Vaclav Petras
<p><i>Last changed: $Date$</i>
+
Modified: grass-addons/grass7/imagery/i.edge/main.c
===================================================================
--- grass-addons/grass7/imagery/i.edge/main.c 2012-08-02 11:27:51 UTC (rev 52500)
+++ grass-addons/grass7/imagery/i.edge/main.c 2012-08-02 12:10:56 UTC (rev 52501)
@@ -22,8 +22,6 @@
#include <grass/raster.h>
#include <grass/glocale.h>
-
-#include <grass/imagery.h>
#include <grass/gmath.h>
#include <math.h>
@@ -70,12 +68,14 @@
for (c = 0; c < ncols; c++) {
cell_value = row_buffer[c];
+ size_t index = ((size_t) ncols * r) + c;
+
if (!Rast_is_d_null_value(&cell_value))
- mat[(ncols * (r)) + c] = cell_value;
+ mat[index] = cell_value;
else
- mat[(ncols * (r)) + c] = 0.0;
+ mat[index] = 0.0;
- if (mat[(ncols * (r)) + c])
+ if (mat[index])
check_reading = 1;
}
}
@@ -91,25 +91,25 @@
\param[in] map map in a matrix (row order)
*/
-static void writeMap(const char *name, int nrows, int ncols, DCELL * map)
+static void writeMap(const char *name, int nrows, int ncols, CELL * map)
{
unsigned char *outrast; /* output buffer */
int outfd;
- outfd = Rast_open_new(name, DCELL_TYPE); // FIXME: using both open old and open new
+ outfd = Rast_open_new(name, CELL_TYPE); // FIXME: using both open old and open new
int r, c;
- outrast = Rast_allocate_buf(DCELL_TYPE);
+ outrast = Rast_allocate_buf(CELL_TYPE);
for (r = 0; r < nrows; r++) {
for (c = 0; c < ncols; c++) {
- int index = r * ncols + c;
+ size_t index = (size_t) r * ncols + c;
- DCELL value = map[index];
+ CELL value = map[index];
- ((DCELL *) outrast)[c] = value;
+ ((CELL *) outrast)[c] = value;
}
- Rast_put_row(outfd, outrast, DCELL_TYPE);
+ Rast_put_row(outfd, outrast, CELL_TYPE);
}
G_free(outrast);
@@ -132,20 +132,21 @@
int kernelWidth;
- float kernelRadius;
+ double kernelRadius;
char *result; /* output raster name */
char *anglesMapName;
- static const float GAUSSIAN_CUT_OFF = 0.005;
+ static const double GAUSSIAN_CUT_OFF = 0.005;
- static const float MAGNITUDE_SCALE = 100.;
+ static const int MAGNITUDE_SCALE = 100;
- static const float MAGNITUDE_LIMIT = 1000.;
+ static const int MAGNITUDE_LIMIT = 1000;
- float lowThreshold, highThreshold, low, high;
+ int lowThreshold, highThreshold, low, high;
- int nrows, ncols, dim_2;
+ int nrows, ncols;
+ size_t dim_2;
// struct History history; /* holds meta-data (title, comments,..) */
struct GModule *module; /* GRASS module for parsing arguments */
@@ -154,7 +155,7 @@
struct Option *input, *output, *angleOutput,
*lowThresholdOption, *highThresholdOption, *sigmaOption;
- int r;
+ size_t r;
/* initialize GIS environment */
G_gisinit(argv[0]); /* reads grass env, stores program name to G_program_name() */
@@ -165,7 +166,7 @@
G_add_keyword(_("canny"));
G_add_keyword(_("edge detection"));
module->description =
- _("Canny edge detector. Region shall be set to input map. "
+ _("Canny edge detector. Region shall be set to input map. "
"Can work only on small images since map is loaded into memory.");
/* Define the different options as defined in gis.h */
@@ -209,11 +210,11 @@
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
- lowThreshold = atof(lowThresholdOption->answer);
- highThreshold = atof(highThresholdOption->answer);
+ lowThreshold = (int) (atof(lowThresholdOption->answer) + 0.5);
+ highThreshold = (int) (atof(highThresholdOption->answer) + 0.5);
- low = (int)((lowThreshold * MAGNITUDE_SCALE) + 0.5);
- high = (int)((highThreshold * MAGNITUDE_SCALE) + 0.5);
+ low = (int) ((lowThreshold * MAGNITUDE_SCALE) + 0.5);
+ high = (int) ((highThreshold * MAGNITUDE_SCALE) + 0.5);
kernelRadius = atoi(sigmaOption->answer);
@@ -249,11 +250,11 @@
G_debug(3, "number of rows %d", cell_head.rows);
- nrows = cell_head.rows;
+ nrows = Rast_window_rows();
- ncols = cell_head.cols;
+ ncols = Rast_window_cols();
- dim_2 = nrows * ncols;
+ dim_2 = (size_t) nrows * ncols;
DCELL *mat1;
@@ -311,12 +312,12 @@
kernelWidth);
- DCELL *magnitude = (DCELL *) G_calloc((dim_2), sizeof(DCELL));
+ CELL *magnitude = (CELL *) G_calloc((dim_2), sizeof(CELL));
- DCELL *angle = NULL;
+ CELL *angle = NULL;
if (anglesMapName != NULL)
{
- angle = (DCELL *) G_calloc((dim_2), sizeof(DCELL));
+ angle = (CELL *) G_calloc((dim_2), sizeof(CELL));
for (r = 0; r < dim_2; r++) {
angle[r] = 0;
@@ -328,7 +329,7 @@
MAGNITUDE_SCALE, MAGNITUDE_LIMIT);
- DCELL *edges = (DCELL *) G_calloc((dim_2), sizeof(DCELL));
+ CELL *edges = (CELL *) G_calloc((dim_2), sizeof(CELL));
for (r = 0; r < dim_2; r++) {
edges[r] = 0;
More information about the grass-commit
mailing list