'''
pathToDir = "../../Images/Chapter3/Input/"
imageName = "Horse.png"

# Read image into array
inputImage, width, height = imageReadL(pathToDir + imageName)

# Show input image
showImageL(inputImage)

# Create image to store the normalization
outputNormalizedImage = createImageL(width, height)

# Maximum and range
maxVal, miniVal = imageMaxMin(inputImage)
brightRange = float(maxVal - miniVal)

# Set the pixels in the output image
for x, y in itertools.product(range(0, width), range(0, height)):

    # Normalize the pixel value according to the range
    outputNormalizedImage[y, x] = round(
        (inputImage[y, x] - miniVal) * 255.0 / brightRange)

# Compute histogram
histogramNormalizedImage = computeHistogram(outputNormalizedImage)

# Show output image and plot histogram
showImageL(outputNormalizedImage)
plotHistogram(histogramNormalizedImage)
Ejemplo n.º 2
0
    imageName = Input image name
    scale = Scale the gray levels
    translation = Value added to the gray levels
'''
pathToDir = "../../Images/Chapter3/Input/"
imageName = "Horse.png"
scale = 1.0
translation = 0.0

# Read image into array
inputImage, width, height  = imageReadL(pathToDir + imageName)

# Transform the image
for x,y in itertools.product(range(0, width), range(0, height)):
    b = int(scale*float(inputImage[y,x]) + translation)
    inputImage[y,x] = max(0, min(b, 255))

# Show transformed image
showImageL(inputImage)

# Vector of integers values to store the number of times a pixel value is repeated
outputHistogram = createVectorI(256)

# Get the number of times a pixel value is found in the image
for x,y in itertools.product(range(0, width), range(0, height)):
    pixelValue = inputImage[y,x]
    outputHistogram[pixelValue] += 1
               
# Plot histogram
plotHistogram(outputHistogram)
numEdges = len(sumArcLenghts)
shapeLenght = sumArcLenghts[numEdges - 1]

# If number descriptors is 0 use the maximum according to the lenght
if numDescriptors == 0:
    numDescriptors = 1 + int(numEdges /2)

# Compute coefficients 
coefficients = createImageF(numDescriptors, 2)
lenghtNorm = 2.0 * pi / shapeLenght
for k in range(1, numDescriptors):
    arcLenght = 0
    for p in range(0, numEdges):
        coefficients[0, k] += cumulativeFunc[p] * (sumArcLenghts[p] - arcLenght)          \
                                                * cos(k * sumArcLenghts[p] * lenghtNorm)
        coefficients[1, k] += cumulativeFunc[p] * (sumArcLenghts[p] - arcLenght)          \
                                                * sin(k * sumArcLenghts[p] * lenghtNorm)
        arcLenght = sumArcLenghts[p]
  
    coefficients[0, k] = coefficients[0, k] *(2.0/shapeLenght)
    coefficients[1, k] = coefficients[1, k] *(2.0/shapeLenght) - (2.0/k)

# Rotation invariant descriptors
descriptors = createVectorF(numDescriptors)
for k in range(0, numDescriptors):
    descriptors[k] = sqrt(coefficients[0, k]*coefficients[0, k] +                         \
                          coefficients[1, k]*coefficients[1, k])

# Plot coefficients and descriptors
plotHistogram(descriptors, [0, 1], .95)
Ejemplo n.º 4
0
# Set the pixels in the output image
for x, y in itertools.product(range(0, width), range(0, height)):
    inputValue = int(inputImage[y, x])

    # Set the pixels in the sawtooth image
    pixelInInterval = inputValue % intevalSize
    gain = float(pixelInInterval) / float(intevalSize)
    outputSawtoothImage[y, x] = inputValue * gain

    # Set the pixels in the Logarithmic
    outputLogarithmicImage[y, x] = 20 * log(inputValue * 100.0)

    # Set the pixels in the Exponential image
    outputExponentialImage[y, x] = 20 * exp(inputValue / 100.0)

# Compute histograms
histogramSawtoothImage = computeHistogram(outputSawtoothImage)
histogramLogarithmicImage = computeHistogram(outputLogarithmicImage)
histogramExponentialImage = computeHistogram(outputExponentialImage)

# Show output images
showImageL(outputSawtoothImage)
showImageL(outputLogarithmicImage)
showImageL(outputExponentialImage)

# Plot histograms
plotHistogram(histogramSawtoothImage)
plotHistogram(histogramLogarithmicImage)
plotHistogram(histogramExponentialImage)
Ejemplo n.º 5
0
# Create histograms to store cumulative moments
w = createVectorF(256)
m = createVectorF(256)

# Create histograms to store separation
separability = createVectorF(256)

# Obtain histograms
normalization = 1.0 / float(width * height)
w[0] = normalization * inputHistogram[0]
for level in range(1, 256):
    w[level] = w[level - 1] + normalization * inputHistogram[level]
    m[level] = m[level - 1] + level * normalization * inputHistogram[level]

# Look for the maximum
maximumLevel = 0
for level in range(0, 256):
    if w[level] * (float(level) - w[level]) != 0:
        separability[level] = float(pow( ( m[255] * w[level] - m[level]), 2)      \
                                   / (w[level] * (float(level) - w[level])))

        if separability[level] > separability[maximumLevel]:
            maximumLevel = level

outputImage = thresholdImage(inputImage, maximumLevel)

# Show output image
showImageL(outputImage)
plotHistogram(separability)
Ejemplo n.º 6
0
                    # More buckets if the points are close
                    for deltaBucket in range(-incAngle, +incAngle + 1):
                        bucket = buketAngleBase + deltaBucket
                        if bucket < 0:
                            bucket = 360 + bucket
                        if bucket >= 360:
                            bucket = bucket - 360

                        w = (incAngle - fabs(deltaBucket)) / float(incAngle)
                        accM[bucket] += w

# Find maximum and plot histogram
maximum, _ = imageMaxMin(accM)
peakThreshold = peakDetection * maximum
plotHistogram(accM)

# Prepare output image as a dark version of the input
outputImage = createScaleImageL(inputImage, 0.5)

# Gather evidence for the r parameter in a second accumulator
peaks = peakDetectorVector(accM, peakThreshold)
for peakIndex in range(0, len(peaks)):
    m = peaks[peakIndex]

    accR = createVectorF(maxLenght)
    angle = (m * pi) / 180.0
    for x, y in itertools.product(range(0, width), range(0, height)):
        if magnitude[y, x] != 0:
            r = fabs((x - cx) * cos(angle) + (y - cy) * sin(angle))
            bucket = int(r)