PGM Format Specification. Updated: 27 November 2013 Table Of Contents pgm - Netpbm grayscale image format This program is part of Netpbm. The PGM format is a lowest common denominator grayscale file format. It is designed to be extremely easy to learn and write programs for. (It's so simple that most people will simply reverse engineer it because it's easier than reading this specification).
A PGM image represents a grayscale graphic image. The name "PGM" is an acronym derived from "Portable Gray Map. " One official variant of PGM is the transparency mask. The format definition is as follows. A PGM file consists of a sequence of one or more PGM images. Each PGM image consists of the following: A "magic number" for identifying the file type. Strings starting with "#" may be comments, the same as with PBM.
Note that you can use pamdepth to convert between a the format with 1 byte per gray value and the one with 2 bytes per gray value. All characters referred to herein are encoded in ASCII. Plain PGM. 2D Convolution. A 2D convolution can be thought of as replacing each pixel with the weighted sum of its neighbors. The kernel is another image, usually of smaller size, which contains the weights. The sum of the weights should be 1 (one). If this is not the case, the sum of the weights can be computed during the summation, and used to scale the result. C++ code for convolution with a kernel of width 3: for ( row = 0; row < HEIGHT; row++ ) { for ( col = 0; col < WIDTH; col++ ) { float accumulation = 0; float weightsum = 0; for ( i = -1; i <= 1; i++ ) { for ( j = -1; j <= 1; j++ ) { unsigned char k = I(row+i, col+j); accumulation += k * kernel[1+i][1+j]; weightsum += kernel[1+i][1+j]; } } I2(row,col) = unsigned char (accumulation/weightsum); } Care must be taken at the edges of the image to avoid accessing memory beyond the image bounds.
You can create a PGM image from a JPEG image using the NETPBM tools: djpeg < myimage.jpg | ppmtopgm >myimage.pgm. Cycle Counters - FFTW 3.3. 10.3 Cycle Counters FFTW's planner actually executes and times different possible FFT algorithms in order to pick the fastest plan for a given n. In order to do this in as short a time as possible, however, the timer must have a very high resolution, and to accomplish this we employ the hardware cycle counters that are available on most CPUs. Access to the cycle counters, unfortunately, is a compiler and/or operating-system dependent task, often requiring inline assembly language, and it may be that your compiler is not supported. If a cycle counter is not available on your system (e.g. some embedded processor), and you don't want to use estimated plans, as a last resort you can use the --with-slow-timer option to configure (on Unix) or #define WITH_SLOW_TIMER in config.h (elsewhere).
Free Software. 2D Pre-Stack Depth Migration 2008: Parallel (MPI) 2D pre-stack depth migration, 2D wavefield extrapolation, and 2D Greens function calculation. All programs make use of WLSQ optimised one-way wavefield extrapolation operators. source code, manual 2D convolution for 3D wavefield extrapolation 2005: 2D convolution routine 2D acoustic/visco-elastic finite difference wavefield modeling. August 2013: Source Code June 2013: fdelmodc Manual Changes: February 2013: better absorbing/tapered boundaries June 2012: ampltiudes of source compliant with analytical expressions January 2012: OpenMP added 2D acoustic/visco-elastic finite difference wavefield modeling + tools for 2D gridded model building and wavelet definition + 2D wavefield extrapolation/migration.
August 2013: Source Code for Finite Difference + Extrapolation migration If you are compiling and running demo and example scripts of the 2D FD code and find any bugs or have suggestions for improvement. 23.2: Dynamically Allocating Multidimensional Arrays. We've seen that it's straightforward to call malloc to allocate a block of memory which can simulate an array, but with a size which we get to pick at run-time.
Can we do the same sort of thing to simulate multidimensional arrays? We can, but we'll end up using pointers to pointers. If we don't know how many columns the array will have, we'll clearly allocate memory for each row (as many columns wide as we like) by calling malloc, and each row will therefore be represented by a pointer. How will we keep track of those pointers? There are, after all, many of them, one for each row. This is best illustrated with an example: #include <stdlib.h> int **array; array = malloc(nrows * sizeof(int *)); if(array == NULL) { fprintf(stderr, "out of memory\n"); exit or return } for(i = 0; i < nrows; i++) { array[i] = malloc(ncolumns * sizeof(int)); if(array[i] == NULL) { fprintf(stderr, "out of memory\n"); exit or return } } array[i][j] func2(int **array, int nrows, int ncolumns) { }
2D Convolution. 1 Introduction2 Theory3 Algorithms 3.1 simple 3.2 symmetric 2D 3.3 symmetric circle 3.4 symmetric and cache4 Performance5 Conclusion6 Links and References 1 Introduction Convolution is a widely used technique in image and signal processing applications. In image processing the convolution operator is used as a filter to change the characteristics of the image; sharpen the edges, blur the image or remove the high or low frequency noise. In seismic processing a convolution can be used to extrapolate the propagating wavefield forward of backward.
Two dimensional (2D) convolutions are sometimes the most time consuming parts of an application. In this article the algorithm for a position dependent symmetric 2D convolution operator is discussed. 2 Theory The convolution operator discussed in this article will be dependent on its spatial position and in that case the Fourier transformation cannot be used. Figure 1: One dimensional convolution in vector-matrix notation. 3 Algorithms 3.1 simple. Fast algorithm for computing matrix multiplication!!!! Mostly people are using this algorithm to compute matrix multiplication: Code: C #define n 1000int main(){ int a[n][n],b[n][n],c[n][n]; c[0][0]=0; for( i=0;i<n;++i) { for(j=0;j<n;++j) { for(k=0;k<n;++k) { c[i][j] = c[i][j] + a[i][k] * b[k][j] } } } return 0;} In this program( a short algo) , every time we are taking one element of an array to catche and processing for it. Means At one time cpu reading one element value of a array and b Array and compute and store to c Array.
To reading every time elements from array , why we are taking some group of element i.e. Block size, then no need to read every element. A groups of element will be on catche and we can do fast as given above algo. Block Algorithm for Matrix Multiplication: C++ - Speed up matrix multiplication. Convolution. Convolution is the most important and fundamental concept in signal processing and analysis.
By using convolution, we can construct the output of system for any arbitrary input signal, if we know the impulse response of system. How is it possible that knowing only impulse response of system can determine the output for any given input signal? We will find out the meaning of convolution. Related Topics: Window FiltersDownload: conv1d.zip, conv2d.zip Definition First, let's see the mathematical definition of convolution in discrete time domain.
Where x[n] is input signal, h[n] is impulse response, and y[n] is output. * denotes convolution. The keystone of understanding convolution is laid behind impulse response and impulse decomposition. Impulse Function Decomposition In order to understand the meaning of convolution, we are going to start from the concept of signal decomposition. In general, a signal can be decomposed as a weighted sum of basis signals. Impulse Response Back to the Definition. Convolution via the Frequency Domain. Suppose that you despise convolution. What are you going to do if given an input signal and impulse response, and need to find the resulting output signal? Figure 9-8 provides an answer: transform the two signals into the frequency domain, multiply them, and then transform the result back into the time domain. This replaces one convolution with two DFTs, a multiplication, and an Inverse DFT. Even though the intermediate steps are very different, the output is identical to the standard convolution algorithm.
Does anyone hate convolution enough to go to this trouble? The second reason for avoiding convolution is computation speed. The standard convolution algorithm is slow because of the large number of multiplications and additions that must be calculated. To start, we need to define how to multiply one frequency domain signal by another, i.e., what it means to write: X[f] × H[f] = Y[f].
Now back to frequency domain convolution. Now consider the more general case in Fig. 9-9. Peter's Functions for Computer Vision. To use these functions you will need MATLAB and the MATLAB Image Processing Toolbox. You may also want to refer to the MATLAB documentation and the Image Processing Toolbox documentation Octave Alternatively you can use Octave which is a very good open source alternative to MATLAB.
Almost all the functions on this page run under Octave. See my Notes on using Octave. An advantage of using Octave is that you can run it on your Android device. MATLAB/Octave compatibility of individual function is indicated as follows Runs under MATLAB and Octave. I receive so many mail messages regarding this site that I have difficulty responding to them all. Please report any bugs and/or suggest enhancements to Acknowledgement: Much of this site was developed while I was with the School of Computer Science & Software Engineering The University of Western Australia I thank them for continuing to host this site.
Cheers, Peter Kovesi. Create structure array - MATLAB. Syntax s = structs = struct(field,value) examples = struct(field1,value1,...,fieldN,valueN) examples = struct([]) Description s = struct creates a scalar (1-by-1) structure with no fields. example s = struct(field,value) creates a structure array with the specified field and values. If value is not a cell array, then s is a scalar structure, where s. (field) = value.If value is a cell array, then s is a structure array with the same dimensions as value. Example s = struct(field1,value1,...,fieldN,valueN) creates a structure array with multiple fields. If none of the value inputs is a cell array, or all are scalar cell arrays, then s is a scalar structure.If any of the value inputs are nonscalar cell arrays, then s has the same dimensions as the nonscalar cell arrays. S = struct([]) creates an empty (0-by-0) structure with no fields. s = struct(obj) creates a structure with field names and values that correspond to properties of obj.
Examples Structure with One Field s.f s(1) s(2) s(1).a = 'a' Separable convolution: Part 2 | Steve on Image Processing. Back in October I introduced the concept of filter separability. A two-dimensional filter s is said to be separable if it can be written as the convolution of two one-dimensional filters v and h: I said then that "next time" I would explain how to determine whether a given filter is separable. Well, I guess I got side-tracked, but I'm back on topic now. This question gave me one of earliest opportunities at The MathWorks to wander down to company co-founder Cleve's office and ask for advice. I asked, "How can I determine if a matrix is an outer product of two vectors? " Cleve was very helpful, as he always is, although I was a little embarrassed afterward that I hadn't figured it out myself. Of course. Dbtype 15:19 rank 15 s = svd(A); 16 if nargin==1 17 tol = max(size(A)') * eps(max(s)); 18 end 19 r = sum(s > tol); So the test is this: The rank of A is the number of nonzero singular values of A, with some numerical tolerance based on eps and the size of A. ans = 1 The Sobel kernel: ans = 5.
Separable convolution | Steve on Image Processing. Contents What is a separable filter? A two-dimensional filter kernel is separable if it can be expressed as the outer product of two vectors. For example, let's look at a Sobel kernel. s = [-1 0 1; -2 0 2; -1 0 1] s = -1 0 1 -2 0 2 -1 0 1 This kernel can be written as a matrix product of a column and a row vector. v = [1; 2; 1] v = 1 2 1 h = [-1 0 1] h = -1 0 1 v * h ans = -1 0 1 -2 0 2 -1 0 1 Associativity of convolution As it turns out, the matrix product of a column vector and a row vector is equivalent to the two-dimensional convolution of the two vectors. conv2(v, h) This matters because convolution is associative. (I've used the asterix here to mean convolution.) Then you can filter with s by filtering first with v, and then filtering the result with h.
Computational advantage of separable convolution Why would you want to filter this way? The computational advantage of separable convolution versus nonseparable convolution is therefore: That's enough for now. 2-D convolution - MATLAB. Syntax C = conv2(A,B)C = conv2(h1,h2,A)C = conv2(...,shape) Description C = conv2(A,B) computes the two-dimensional convolution of matrices A and B.
If one of these matrices describes a two-dimensional finite impulse response (FIR) filter, the other matrix is filtered in two dimensions. C = conv2(h1,h2,A) first convolves A with the vector h1 along the rows and then with the vector h2 along the columns. C = conv2(...,shape) returns a subsection of the two-dimensional convolution, as specified by the shape parameter: Examples Shape for Subsection of 2-D Convolution For the 'same' case, conv2 returns the central part of the convolution.
This example first computes the convolution of A using the default ('full') shape, then computes the convolution using the 'same' shape. Extract Edges from Raised Pedestal In image processing, the Sobel edge finding operation is a two-dimensional convolution of an input array with the special matrix: s = [1 2 1; 0 0 0; -1 -2 -1]; V = conv2(A,s'); figure, mesh(V) Timm's dev blog OpenCV: Equivalent to Matlabs conv2() function. Home > Computer Vision > OpenCV: Equivalent to Matlab’s conv2() function The numerical computing environment Matlab (or e.g. its free alternative GNU Octave) provides a function called conv2 for the two-dimensional convolution of a given matrix with a convolution kernel.
While writing some C++ code based upon the free image processing library OpenCV, I found that OpenCV currently offers no equivalent method. Although there is a filter2D() method that implements two-dimensional correlation and that can be used to convolute an image with a given kernel (by flipping that kernel and moving the anchor point to the correct position, as explained on the corresponding OpenCV documentation page), it would be nice to have a method offering the same border handling options as Matlab (“full”, “valid” or “same” convolution), e.g. for comparing results of the same algorithm implemented in both Matlab and C++ using OpenCV. Here is what I came up with: