1611738720

# Histogram Equalization and CLAHE

If the image histogram is confined only to a small region (low contrast images), histogram equalization can be used to stretch the histogram to include all ranges. But, this type of stretching may not result in ideal results and gives too bright and too dark regions in the image. This can be especially very bad for images with large intensity variations.

Contrast limited adaptive histogram equalization (CLAHE)
Regular histogram equalization uses global contrast of the image. This results in too bright and too dark regions as the histogram stretches and is not confined to specific region.

Adaptive histogram equalization divides the image into small tiles and within
each tile the histogram is equalized. Tile size is typically 8x8. If the image contains noise, it gets amplified during this process. Therefore,
contrast limiting is applied to limit the contrast below a specific limit. Bilinear interpolation is performed between tile borders.

This tutorial demonstrates the use of histogram equalization and CLAHE in Python to enhance low contrast images.

The code from this video is available at: https://github.com/bnsreenu/python_for_microscopists

#python #machine-learning #deep-learning

1603119600

## Histogram Matching

The code is available here on Github.

### What is an image histogram?

Before start defining the histogram, for simplicity, we use grayscales images. Then later I explain the process for the color images as well.

The image histogram indicates the intensity distribution of an image. In other words, the image histogram shows the number of pixels in an image having a specific intensity value. As an example, assume a normal image with pixel intensities varies from 0 to 255. In order to generate its histogram we only need to count the number of pixels having intensity value 0, then 1 and continue to the 255. In Fig.1, we have a sample 5*5 image with pixel diversities from 0 to 4. In the first step for generating the histogram, we create the Histogram Table, by counting the number of each pixel intensities. Then we can easily generate the histogram by creating a bar chart based on the histogram table.

### How to generate an image histogram?

In python, we can use the following two functions to create and then display the histogram of an image.

``````import matplotlib.pyplot as plt
import numpy as np

def generate_histogram(img, do_print):
"""
@params: img: can be a grayscale or color image. We calculate the Normalized histogram of this image.
@params: do_print: if or not print the result histogram
@return: will return both histogram and the grayscale image
"""
if len(img.shape) == 3: ## img is colorful, so we convert it to grayscale
gr_img = np.mean(img, axis=-1)
else:
gr_img = img
'''now we calc grayscale histogram'''
gr_hist = np.zeros([256])

for x_pixel in range(gr_img.shape[0]):
for y_pixel in range(gr_img.shape[1]):
pixel_value = int(gr_img[x_pixel, y_pixel])
gr_hist[pixel_value] += 1

'''normalizing the Histogram'''
gr_hist /= (gr_img.shape[0] * gr_img.shape[1])
if do_print:
print_histogram(gr_hist, name="n_h_img", title="Normalized Histogram")
return gr_hist, gr_img

def print_histogram(_histrogram, name, title):
plt.figure()
plt.title(title)
plt.plot(_histrogram, color='#ef476f')
plt.bar(np.arange(len(_histrogram)), _histrogram, color='#b7b7a4')
plt.ylabel('Number of Pixels')
plt.xlabel('Pixel Value')
plt.savefig("hist_" + name)
``````

Most of the time when we create a histogram, we normalize the histogram by dividing the number of pixels with each intensity value by the normalizing factor which is the multiplication of the image width and image height. For ease of use, if the input image of the generate_histogram function is a color image, we first convert to a grayscale image(see line## 6).

#computer-vision #histograms #image-processing #python #histogram-equalization

1599641040

## Java String Equals Example | String equals() In Java

In Java, objects of strings are immutable, so that means we cannot once the string is created. Now, if we have two strings and we want to compare them if they are the same or not, then we can use the equals()method.

### Java String Equals Example

Java String equals() method compares the two given strings based on the content of a string.

If any character is not matched, then it returns false and if all characters are matched, it returns true.

1. Java String equals() method overrides an Object class equals() method implementation.
2. Java String is immutable, checking the equality of string to another object should be done using equals() method rather than == operator.
3. String equals() method always returns a boolean value; it doesn’t throw any exceptions.
4. The result of the equals() method is true if and only if an argument is not null, it’s the String object, represents the same sequence of characters as this string.

See the following syntax.

``````string1.equals(string2);
``````

#java #java string equals #equals

1601661070

## What is the difference between = (single equal to) and == (double equal to)?

What is the difference between = (single equal to) and == (double equal to)?

• The = (single equal to) is use to assign the value on the right to a variable
on the left.

• The == (double equal to) is use to compare to two values.

Explained By DDSRY

#difference between #singe equal to #double equal to #python #programming #developer

1598729340

## Python String Equals Example | Python String Comparison

Python String comparison can be performed using equal (==) and comparison (<, >, !=, <=, >=) operators. There are no particular functions to compare two strings in Python. Strings in python are contiguous series of characters delimited by single or double-quotes. Python doesn’t have any separate data type for characters, so they are represented as a single character string.

### Python String Equals

The equal operator is used to compare two strings. It compares one by one character of both strings. When different characters are found in string, then their Unicode value is compared. In Python, the character with lower Unicode value is considered to be smaller and higher unicode value considered to be higher.

#python #equals #python string equals

1599492000

## Python Not Equal Operator Example | Not Equal in Python

Python not equal is an inbuilt operator returns True if two variables are of the same type and have different values, if the values are identical, then it returns False. The not equal operator is a comparison operator in Python. For comparing object identities, you can use the keyword is, and its negation is not.

### Python Not Equal Operator

Python is dynamic and strongly typed language, so if the two variables have the same values, but they are of a different type, then not equal operator will return True.

#python #not equal