Postagens

Classical Computer Vision: The Spatial Domain II - Morphological Transformations

Imagem
   M orphological Transformations are simple operations generally applied to binary images using convolution as a base to transform the image.     T here are two basic operations: erosion and dilation. The other morphological transformations are a composition of those two operations and the image itself.     Erosion     The basic idea of erosion is to "erode" away the boundaries of the "white" image. It works by trying to expand the black area, consuming the foreground image edges. So,    all the pixels near boundary will be discarded depending upon the size of kernel. import numpy as np import skimage import skimage . io as io from skimage . color import rgb2gray from skimage . morphology import erosion import matplotlib . pyplot as plt import cv2 if __name__ == '__main__' : image = skimage .util.invert( rgb2gray ( io . imread ( 'plate.png' ))) plt . imshow ( image , cmap = 'gray' ) plt . show () k...

Classical Computer Vision: The Spatial Domain I - The Convolution Operation

Imagem
     The Spatial Domain for Image Processing is the domain where a pixel is seen as a member of a group of pixels, in opposition to the Value Domain, where a pixel was seen as a unique entity.     Therefore, when we work in the spatial domain, we try to extract geometrical information from the image. We are concerned about borders, segmentation, morphology, filters etc.        The Convolution Operation     What is a convolution?      Mathematically speaking, a convolution is a type of matrix operation involving  two matrices that are generally  bi-dimensional, where one matrix is the image and the other is  the convolution matrix , also known as  the structuring element .     The goal here is to transform the first matrix using the second one as a tool for changing its values.       We could think of the convolution matrix as a piece of code and the image as the input ...

Classical Computer Vision: Similarity Measures in Images

Imagem
 Why Measure Similarity?     One of the most important things we do when looking into an image is classification. We look at something and our brain tries to give it a meaning.     Sometimes, we classify things by inferring it based on something else. Something that is similar  to what we previously know.      The same thing happens to computer vision. Let's imagine that we have an image-A that we know what it is: it's a car. If image-B is another car, but with a different color. Don't we wish that computers, somehow, were able to infer that image-B is also a car, just because it's so similar to A?     Image Similarity tries to tackle with this problem. The goal here is to extract from two images  a comparable rank with which we could say that image-A is probably the same image as B, or at least it's very close to B.      One of the ways to do that is to use algorithms to calculate similarity or image distancing ...

Classical Computer Vision: Value Domain III: Point Operations

Imagem
What is a Point Operation?      We could see the value domain transformations as point operations. A point operation is an operation that modifies a pixel without affecting the neighboring ones. It doesn't change the size, structure or geometry of the image, and also, it isn't based on any particular aspect of the information inside the image. It just acts blindly upon every pixel. Point Operations with Scalars     By using point operations between pixels and scalars, we can make several simple changes in the image, such as modifying  brightness, contrast etc.     As an example of this, let's check the code below: from skimage import io import matplotlib . pyplot as plt def trunc ( px ): if px > 255 : return 255 if px < 0 : return 0 return px def point_op ( image , fn ): for row in range ( 0 , image .shape[ 0 ]): for col in range ( 0 , image .shape[ 1 ]): res = fn...

Classical Computer Vision: Value Domain II: Threshold

Imagem
 Thresholding     Thresholding is the simplest segmentation method.      Imagine that I have an object in an image and I want to segment it from the background. The thresholding i s based on the variation of intensity between that object and the background.     Basically, we compare the pixel value to a threshold value and take an action. For example, we could put 0 for every pixel that is equal or lower than the  threshold. import matplotlib . pyplot as plt import skimage . io as io from skimage import data , color from skimage . transform import rescale , resize , downscale_local_mean from skimage . filters import threshold_mean import numpy as np apple_original = io . imread ( "red-apple-1326427.jpg" ) print ( apple_original .shape) plt . imshow ( apple_original ) plt . show () def image_binary_threshold ( image , min_thr , max_thr ): res = image .copy() for i in range ( 0 , 3 ): k = res [:, :, i ] ...

Classical Computer Vision: Value Domain

Imagem
     Let's now focus on the Value Domain of image processing.     In this domain, we can just apply filter and simplification to images, since we are dealing with each pixel individually, in an out of context fashion.     Let's explore some of the  techniques available in this domain Image Windowing     One of the most interesting techniques we have in the value domain is image windowing. Let's take medical radiodensity images as an example that the use of this resource is imperative.      Since we are unable to recognize 4000 shades of gray right on the spot, we can use this technique to focus on a single property of the image we are analyzing. Therefore, we  limit the number of Hounsfield units (which is the gray scale that describes radiodensity images) that a human or a computer is processing.      In practical terms, is a change of perspective. Sometimes we are analyzing the soft tissue, ...