What is Non Redundant LBP in texture description? - c++

I want to know about non redundant local binary pattern for texture description. What is the difference between original LBP and non-redundant LBP in texture description?
Can someone clarify the above mentioned topic through a good example?

Non-redundant Local Binary Patterns (NRLBP) descriptor considers the LBP code and its complement as the same pattern, and hence the number of bins in the LBP histogram is reduced by half (see this paper for further details).
The following toy example might help you figure out how NRLBP works. Consider an image of just 3 rows and 4 columns with the intensity levels shown below:
There are only two LBP codes in this image, namely:
Thus, the LBP representation of the image is a feature vector of 256 components. The bins corresponding to patterns 101010102=170 and 010101012=85 take the value 0.5 and the remaining bins are zero (I'm assuming that the histogram is normalized).
The NRLBP representation of the image turns out to be a feature vector of 128 components. As both patterns are 1's complement of each other, they are actually the same pattern in this texture model and thus the only nonzero bin corresponds to the pattern code 85 and takes the value 1.

Related

Pack pixels in 1bit/bw/binary image in boxes

I need an algorithm that, from a 1bit 2D image (a 2D matrix of mixed 1s and 0s) returns me rectangles (with the x,y coordinates of each corner) that packs the pixels that are equal to zero, using the least amount of boxes.
So for an image like
0000000
1111111
1111111
1111110
1111100
0000000
It would return something like
Rectangle 1 ((0,0),(0,1),(7,0),(7,1))
Rectangle 2 ((6,3),(7,3),(7,4),(6,4))
Rectangle 3 ((5,4),(7,4),(7,6),(5,6))
Rectangle 4 ((0,5),(0,6),(7,6),(7,5))
I feel this algorithm exists, but I am unable to Google it or name it.
I'm guessing you're looking to make a compression algorithm for your images. There isn't an algorithm that guarantees the minimum number of rectangles, as far as I'm aware.
The first thing that comes to mind is taking your pixel data as a 1D array and using run-length encoding to compress it. Images tend to have rather large groupings of similarly-colored pixels, so this should give you some data savings.
There are some things you can do on top of that to further increase the information density:
Like you suggested, start off with an image that is completely white and only store black pixels
If encoding time isn't an issue, run your encoding on both white and black pixels, then store whichever requires less data and use one bit to store whether the image should start with a black or a white background.
There are some algorithms that try to do this in two dimensions, but this seems to be quite a bit more complex. Here's one attempt I found on the topic:
https://pdfs.semanticscholar.org/d09a/62ea3472352bf7bbe873677cd81f348206cc.pdf
I found more interesting SO answers:
What algorithm can be used for packing rectangles of different sizes into the smallest rectangle possible in a fairly optimal way?
Minimum exact cover of grid with squares; extra cuts
Algorithm for finding the fewest rectangles to cover a set of rectangles without overlapping
https://mathoverflow.net/questions/244718/algo-for-covering-maximum-surface-of-a-polygon-with-rectangles
https://mathoverflow.net/questions/105837/get-largest-inscribed-rectangle-of-a-concave-polygon
https://mathoverflow.net/questions/80665/how-to-cover-a-set-in-a-grid-with-as-few-rectangles-as-possible
Converting monochrome image to minimum number of 2d shapes
I also read on Covering rectilinear polygons with axis-parallel rectangles.
I even found a code here: https://github.com/codecombat/codecombat/blob/6009df26de7c7938c0af2122ffba72c07123d172/app/lib/world/world_utils.coffee#L94-L148
I tested multiple approaches but in the end none were as fast as I needed or generated a reasonable amount of rectangles. So for now I went with a different approach.

Histogram calculation for variance local binary pattern (VLBP) in OpenCV C++

I want to calculate the histogram for Variance local binary pattern of a gray scale image using OpenCV C++.
Can someone explain me how to exactly find histogram for variance LBP in OpenCV C++ and what exactly it means?
Also please provide some links that are useful in this case.
VAR is a rotation invariant measure of local variance (have a look at this paper for a more in-depth explanation) defined as:
where P is the number of pixels in the local neighbourhood and μ is the average intensity computed across the local neighbourhood.
LBP variance (LBPV) is a texture descriptor that uses VAR as an adaptive weight to adjust the contribution of the LBP code in histogram calculation (see this paper for details). The value of the kth bin of the LBPV histogram can be expressed as:
where N and M are the number of rows and columns of the image, respectively, and w is given by:
According to this answer the code for calculating LBP using OpenCV is not available for public use, but here you can find a workaround to make that function accesible.

opencv clahe parameters explanation

I would like to know proper explanation of the clahe parameters
i.e clipLimit and tileGridSize.
and how does clipLimit value effects the contrast of the image and what factors(like image resolution, object sizes) to be considered to select tileGridSize.
Thanks in advance
this question is for a long time ago but i searched for the answer and saw this,then i found some links which may help,obviously most of below information are from different sites.
AHE is a computer image processing technique used to improve contrast in images. It differs from ordinary histogram equalization in the respect that the adaptive method computes several histograms, each corresponding to a distinct section of the image, and uses them to redistribute the lightness values of the image. It is therefore suitable for improving the local contrast and enhancing the definitions of edges in each region of an image.
and , AHE has a tendency to over-amplify noise in relatively homogeneous regions of an image ,A variant of adaptive histogram equalization called contrast limited adaptive histogram equalization (CE) prevents this by limiting the amplification.
for first one this image can be useful:
CLAHE limits the amplification by clipping the histogram at a predefined value (called clip limit)
tileGridSize refers to Size of grid for histogram equalization. Input image will be divided into equally sized rectangular tiles. tileGridSize defines the number of tiles in row and column.
it is opencv documentation about it's available functions:
https://docs.opencv.org/master/d6/db6/classcv_1_1CLAHE.html
and this link was good at all:
https://en.wikipedia.org/wiki/Adaptive_histogram_equalization#Contrast_Limited_AHE
http://www.cs.utah.edu/~sujin/courses/reports/cs6640/project2/clahe.html
clipLimit is the threshold value.
tileGridSize defines the number of tiles in row and column.
More Information

OpenCV HOGDescriptor return value

Why does the HOG descriptor returns a vector of float and not int? It's suppose to return a histogram..
To complement the previous answers that are right in my opinion, according to this HoG note I found clearer than the initial Dalal & Triggs paper, there are two normalization steps involved:
Block Normalization
Group the cells into overlapping blocks of 2 x 2 cells each, so that
each block has size 2C x 2C pixels. Two horizontally or vertically
consecutive blocks overlap by two cells, that is, the block stride is
C pixels. As a consequence, each internal cell is covered by four
blocks. Concatenate the four cell histograms in each block into a
single block feature b and normalize the block feature by its
Euclidean norm.
HOG Feature Normalization
The final normalization makes the HOG feature independent of overall
image contrast.
There should be also a bilinear interpolation voting between two consecutive bins to prevent quantization artifacts.
Also, it cannot be an int as you do not only count the number of gradient vectors that fall in a bin but add also the gradient magnitude.
I believe that #Micka is right: the histograms are probably normalized (maybe not to 1). On the Wikipedia page on HOG Descriptors, it is written that:
For improved accuracy, the local histograms can be contrast-normalized by calculating a measure of the intensity across a larger region of the image, called a block, and then using this value to normalize all cells within the block. This normalization results in better invariance to changes in illumination and shadowing.
Hence the need for a vector<float> instead of vector<int>.

MagickQuantizeImage usage

I am processing some images using ImageMagick library. As part of the processing I want to minimize the number of colors if this doesn't affect image quality (too much).
For this I have tried to use MagickQuantizeImage function. Can someone explain me whow should I choose the parameters ?
treedepth:
Normally, this integer value is zero or one. A zero or one tells Quantize to choose a optimal tree depth of Log4(number_colors).% A tree of this depth generally allows the best representation of the reference image with the least amount of memory and the fastest computational speed. In some cases, such as an image with low color dispersion (a few number of colors), a value other than Log4(number_colors) is required. To expand the color tree completely, use a value of 8.
dither:
A value other than zero distributes the difference between an original image and the corresponding color reduced algorithm to neighboring pixels along a Hilbert curve.
measure_error:
A value other than zero measures the difference between the original and quantized images. This difference is the total quantization error. The error is computed by summing over all pixels in an image the distance squared in RGB space between each reference pixel value and its quantized value.
ps: I have made some tests but sometimes the quality of images in severely affected, and I don't want find a result by trial and error.
This is a really good description of the algorithm
http://www.imagemagick.org/www/quantize.html
They are referencing the command-line version, but the concepts are the same.
The parameter measure_error is meant to give you an indication of how good an answer you got. Set to non-zero, then look at the Image object's mean_error_per_pixel field after you quantize to see how good a quantization you got.
If it's not good enough, increase the number of colors.