Wednesday, June 9, 2021

The rewarding virtue of humility

It's commonplace today to see angry drivers giving away to road rage. People are getting triggered pretty much by anything that comes across as making them look less important. We are living in a world where many are self-centered, demanding, egotistic, easily offended, envious, and often insecure about their position in the community. They think that they deserve some sort of trophy, admiration, or approval from others, even without any achievements that call for such. The end result is that people are being gripped by insecurity, fear, anger, rage, sadness, and emotional pain.

At the root of many of these problems is the lack of humility. I've been wanting to write on this for a while, knowing that putting together my thoughts on this is not only going to benefit myself but also others who are looking to develop this endearing quality. Perhaps it is one of the hardest virtues of all. I will try to define humility and contrast it with pride. I will also highlight the strong relationship between humility and one's overall state of happiness. 

  • A humble person does not need constant admiration or approval from others. He is self-contained; his happiness is not dependent on how he is viewed by others. He likes to keep a low profile and stay out of the limelight. However, a proud person expects constant showers of praise. He likes to be the center of attention. It is like oxygen for him; he cannot live without it. He is a slave to his insecurities.
  • A humble person is not easily offended, because he has balanced self-esteem. Other people's opinions are irrelevant to his joy in life and have no bearing on his self-worth. In contrast, a proud person typically has either very low self-esteem or very high self-esteem. When pride is due to low self-esteem, it can create self-hatred and worthlessness, so to hide his insecurities, he tries to live in a fantasy world, where he is the center of attention and the world is revolving around him. When pride is due to very high self-esteem, he considers himself special and therefore entitled to receive special treatment. In both cases, they fall in love with a hyped-up version of themselves.
  • A proud person thinks that he is more important, he knows everything, he is always correct, and nobody is qualified to tell him that he is wrong. He judges others with a self-righteous attitude and a rigid standard of his own. Any remarks or actions of others that are considered a threat to his imagined superiority trigger an instant negative emotional reaction and denial.
  • A proud person is often envious of others and believes that others must be envying him. Since a proud person bases his happiness on his status, popularity, fame, or position, he assumes that others must be evaluating success based on such things and therefore must be envying his supposed success. When he sees others doing better and leading a happy life, even without things he uses to measure success, it makes him sad, jealous, and upset. So he tries to discredit and talk down to others. He is critical of others and rejoices in the downfall of those he envies.
  • A proud person tries to punch beyond his weight by pursuing a high-end career, home, vehicle, or a highly sought education not because he is capable or can afford it, but to showcase his alleged greatness. On the other hand, when humble people pursue those things, it is only because they can afford them, are capable, and enjoy what they are doing, perhaps as a hobby. Humble people have nothing to prove to others. They clearly know what they can do, but also, what they are not able to do. 
  • A humble person recognizes that everything he has is given to him and is not a product of his own work. Whether it's beauty, appearance, strength, intelligence, or talents, he recognizes that it is determined genetically and he didn't have any control over it. He may have been fortunate to be raised with good parents and a good background. He also recognizes that others may have inborn gifts in different ways, such as in music, arts, humor, or imagination that he doesn't have, and are happy to see others doing good with their talents. He doesn't compare himself with others.
  • A proud person dominates conversations and often brags, inflates his abilities, and boasts about his achievements. While not openly boasting, he may subtly make sure that others come to know of his strengths and achievements. In his eyes, only his opinion should matter and he is the one and only awesome personality in the room. He is offended when others interrupt him, even when others do that with good intentions or out of excitement. In contrast, a humble person is quick to listen, slow to speak, and does not indulge in self-advertising. He is mild-tempered and patient.
  • A proud person cannot stand any kind of joke about him in casual conversations. He takes it personally. However he may often make fun of others, but when others do the same to him, he is offended. He is hypersensitive to anything that comes across as negatively affecting his image and prestige.
  • A proud person pretends to be an expert in unrelated fields. He gives opinions on topics that he is not sure of. When someone talks about an interesting topic or personal experience, he may try to make their story less appealing by flaunting his own knowledge or superior experience. A humble person would rather let others talk, and when needed, only talks about things he knows, while also acknowledging things he doesn't know.
  • A humble person is less insecure or anxious about the past or future. Because he is not constantly worried about what others are thinking about him; it doesn't matter if others view him in high regard. Of course, that doesn't mean he is a jerk; he is considerate of others' feelings and strives to maintain a good relationship with everyone. But at the end of the day, his reputation among fellow mortal humans, who are nothing but a mere breath and a speck of dust, is not that important. 
  • A humble person is neither ambitious nor materialistic. So he is not working sixteen hours a day to become the next richest man or celebrity. This gives him more time to focus on other things that give him joy, and less stress in life. He knows that life is short, and there are other rewarding pursuits to focus on. He is content and satisfied with his provisions. On the other hand, since proud people set expectations so high for career, prestige, and material wealth and use them as a marker for success, when reality strikes, it leads to emotional pain, stress, and a dejected feeling that they are a failure.
  • A polite person is not necessarily humble. In some cultures, people naturally display politeness and deference as part of their etiquette and so appear to be unassuming on the outside, but it's not to be confused with humility. Their true color will come out sooner or later. A humble person respects others but doesn't get mad if others don't respect him in return. While respect from others is nice to have, it is not a necessity for his happiness. The absence of respect from others has no effect on a humble person's overall joy in life. Due to this reason, on first impression, a humble person may come across as rude, because he may treat others the way he is okay to be treated; a direct approach without any mock humility, fake politeness, or flattery. 
  • Age does not make a person humble, but true wisdom does. In fact, a person can become haughty as they age, like a chronic disease that is hard to get rid of, stabbing themselves with many pains. He may look down on young people and become insecure about giving up his cherished position to them. Conversely, as teenagers, many of us lacked the maturity and wisdom that result in humility, which explains why we can relate to being a bit arrogant in our younger days. But as time pass by, wisdom is gained through humbling life experiences, study, meditation, and prayer. 
  • A proud person is unwilling to do menial tasks and expects others to take care of him and comply with his wishes. He takes others for granted, never acknowledging others' good contributions in his life. He lacks genuine love for his close ones and can't empathize with their sufferings, even when it's caused by his own actions. He plays the victim card as a reason for his bad behavior and invokes self-pity to gain sympathy from others without taking responsibility for his actions. He is manipulative, he misuses and overreaches his authority, encroaching upon others' rights, responsibilities, or even possessions.
  • A humble person readily acknowledges his faults, apologizes, and won't hesitate to say "I am sorry" when needed. He knows that he is imperfect and makes mistakes. He forgives others and is eager to make peace, even when he is on the right. When someone corrects him, he doesn't worry that by accepting the counsel he somehow becomes less of a person. He tries to take correction objectively. He considers others superior to him in many ways. But others being better than him has nothing to do with his joy in life. In contrast, a proud person immediately gets into defensive mode. He is very insecure about accepting correction. He panics that it will affect his reputation amongst his peers and his future prospect of privileges and position. His inflated ego prevents him from making peace, and he hardens his neck. He is bitter; he harbors resentment and hatred for those he had issues with. 
  • A proud person may humiliate others publicly for their mistakes just to show his power, intelligence, and control. But if anyone dares to do the same back to him, he attacks them personally, bullying and blaming others for his own mistakes. A humble person is patient and talks privately to the person if something needs to be addressed.
  • A proud person does not like to genuinely praise others for their talents. He doesn't believe that other people can be better than him. So he often stamps others down by saying things like, "He is okay" or "He is mediocre". Even if he does praise others, it's not genuine, it's done only to get praise back in return. In contrast, a humble person offers genuine praise and does not expect anything in return. 
  • A humble person does not hold rich ones, celebrities, scientists, or those with positions of authority in adulation, undue respect, or awe. In other words, he does not idolize them as demigods, follow them as superhumans, or take their words as the ultimate authority on unrelated matters. He recognizes that their accomplishments in their respective fields are primarily due to the natural gifts they were bestowed with, whether it's talents, intelligence, beauty, or inherited wealth. They were fortunate to make good use of those gifts. All glory belongs to God who gave them such gifts. This insight prevents a humble person from showing favoritism to such people, making friendships with them for personal advantage, or becoming a sycophant to them; he treats everyone with impartiality.
  • A proud person may boast about his connections with influential people. He likes to hang out only with people that he considers being of his status or above. This is done mostly to prop up his self-worth and possibly to take advantage of them. He may say things like "You gotta hang out with the big shots". In contrast, a humble person has real friends. His friend circles are from all sorts of people, even if it is a few. Who would like to be hanging out with someone who is constantly bragging about oneself or one who is easily offended, and throwing tantrums? But humble people are easy to deal with so end up having real friends.
  • A humble person is also modest, he clearly knows his limitations. He knows exactly what he is capable of and is confident about it. But he also knows what he is not capable of. So he doesn't say "Yes" to any tasks people ask him to do. He does not put himself in an embarrassing situation where he is publicly humiliated for exaggerating his abilities. It also saves him an awful lot of time and from undue stress, because he is not forced to work hard on things he is not good at just to impress others.
  • A proud person rebels against authority, established laws, and order. He thinks nobody is above him, and there shouldn't be any. He stirs up the competition by knocking others down in organizations that he is a member of. He is determined to climb up the ladder. He covets others' positions and authority. He forgets that except for God, everyone else in the universe is under some form of authority and control. He fails to see that even in the secular world everyone is under the control of some authority or law; people are under the government and courts' authority, and in families, children are under their parent's authority. Even more, one cannot violate the authority of laws of nature, such as the law of gravity. One cannot have full control of his health or lifespan. There is no such thing as absolute freedom. A humble person is wise enough to recognize this and his limitation. Nobody can climb up the ladder beyond a certain point, and if left unleashed, there is no end to one's ambition. So a humble person is not having a rebellious or competitive spirit. He works within the boundaries of his freedom, is happy to be wherever in the hierarchy, and never thinks the boundary is too restrictive for his imagination or enjoyment in life.
  • A humble person is happy because he doesn't base happiness based on status, reputation, or position. Even if he hits rock bottom with those things, he has an inner joy and self-respect that cannot be taken away. His delight is in maintaining a good conscience, satisfying his intellectual and spiritual needs, enjoying the fruitage of his labor, having proper recreation, enjoying friendships and being benevolent and helpful to others. Those things are a constant source of joy, which cannot be taken away and provide a baseline of happiness. Anything more, such as appreciation from others or being respected in the community only adds on top of that baseline, like icing on the cake. In contrast, proud people can only put a pretense of happiness.
Finally, a humble person does not think he is truly humble or wise. So the first step toward humility is perhaps to be humble and wise enough to acknowledge that there is a problem. He recognizes that it's an ongoing challenge and a lifelong endeavor. He often reflects on what he did each day which may indicate an area that he needs to work on. To weed out pride, he ponders the real motivation behind his words and actions. He can recall various instances in life where he was prideful and regrets his conduct. Nobody on earth can be perfectly humble, so he forgives himself and others. He learns from his failures. From his standpoint, the more humble he is, the happier he is.

N.B: This is my personal take on this subject, so I could be wrong☺. I may revise this article when I have more thoughts on this. For the sake of brevity, I am using masculine pronouns, but it applies to both genders.

Thursday, January 18, 2018

Verifying RSA decryption equation

I was reading Wikipedia on RSA algorithm for asymmetric key encryption. At first, with the absence of a lengthy proof, the decryption equation seemed like magic. I tried to verify quickly that raising the encrypted message (cipher) to the exponent and then doing a modulus with n will return the original message. I am posting my result below.


Monday, February 20, 2017

Treasure in home town

About five years ago, I woke up with the news that surprised many in the city of Trivandrum (Thiruvananthapuram). It is the capital of the state of Kerala located in extreme southwest India. I grew up around 15 miles down south from the city, I lived there until my move to the United States in 2011. Archaeologists just unearthed treasures worth over $1 trillion US dollars in a much-overlooked temple in the middle of the city. 

Who in the world would have thought that just another Hindu temple—among the thousands in Kerala—that anybody can walk in hosted a grand treasure in its secret vaults underneath? Looks like a perfect setting for another Indiana Jones movie is in making. The temple in the spotlight is called Sree Padmanabha Swamy Temple. It was built around the 16th century and was dedicated to Padmanabha Swamy, a Hindu deity revered by the erstwhile royal family of Travancore. When India got independence from the British in 1947 both the Travancore and neighboring Cochin kingdoms joined the Indian Union, and later, the Malayalam speaking region all together formed the state of Kerala. Since then the temple's notoriety diminished; as the royal family lost its grandiose their chief deity became less relevant to people. 





As a boy, I have been personally around the temple many times for attending the teaching programs of Jehovah's Witnesses in a close-by auditorium. The temple was easily accessible to the public. Of course not after the discovery; now protected with machine guns, security cameras, motion detectors, and seismic sensors. To mention a few, the items discovered in four vaults included golden idols studded with diamonds and other precious stones, a gold sheaf weighing over 1000 pounds, an 80-pound golden veil, hundreds of thousands of gold coins, golden artifacts, necklaces, diadems, rubies, sapphires, emeralds, and other precious gemstones. Upon objection from temple priests who cited "bad omens", the remaining two vaults were left unopened.  Subsequently, the Supreme Court of India which had earlier directed archaeologists to make an inventory of the vaults put the matter on hold.

To give a comparison, being one of the largest economies in the world the net GDP of the present Indian economy is around $1.87 trillion USD. But researchers are estimating this treasure by antique value to be worth over $1 trillion USD. It is believed that the treasure is an accumulation of wealth over the past two millenniums by trade, tax, and gifts to the royal family and their predecessor kingdoms. Gold has a major role in Indian women's adornment, and even today India's obsession with gold and precious stones is well-known. Likely, when British colonies were established around the 17th century, the rulers who were aware of this treasure put it in secret vaults underneath their much-revered temple to protect against plundering. Today, there is already a debate among the public as to how this treasure should be used. While some suggest that it should be used for public welfare, others dissent, and opine that it belongs to the temple and should be left alone. Meanwhile, the descendants of the royal family are also claiming a stake in the wealth, opposing the current ownership by the Kerala state government. The entangling legal dispute is currently pending before the Supreme Court of India.

As someone interested in the history of Christianity and biblical archaeology in general, among the discoveries that particularly stroke me were over one hundred thousand gold coins dating back to the 1st century Roman Empire with imprints of contemporary Caesars. No wonder, Roman politicians and historians are on record decrying the loss of silver and gold to buy commodities from India to pamper Roman wives. 

It is undisputed that Christianity in India existed at least from the 5th century AD. However, Saint Thomas Christians, an ancient community of Christians in Kerala, trace back their origins to the 1st century AD. The doctrines and practices of modern-day Saint Thomas Christians don't differ much from that of Roman Catholics, with tradition and creed superseding scriptural authority. They assert by tradition that Thomas the apostle of Jesus traveled to South India and convinced their ancestors to convert to Christianity. Though it is a possibility, there is no solid evidence or record for this. The Bible does mention India a few times such as in the Book of Esther as a boundary for the 4th century BC Persian empire by Xerxes I, and in the Book of Revelation using the words "Indian spice". Neither does it mention much about the activity of Thomas the apostle after Jesus' death and resurrection. Regardless, a number of 3rd and 4th-century Roman writers attest to Thomas's trip to India. 


Another fact is that there is an ancient body of Jews in Kerala called Cochin Jews, most immigrated to modern Israel after the independence of India from the British in 1947. They claim that their ancestors arrived in Kerala during the time of King Solomon to do trade. In the Bible, we read accounts of King Solomon having a fleet of trading ships which bought from far lands among other things peacock, notorious to the Indian subcontinent. Though we are not sure if they lived in Kerala during Solomon's time in the 10th century BC, historians agree that Cochin Jews existed at least since the 1st century AD. So it is possible that Jewish missionaries in the first century joined Jewish merchants, to reach the shores of Kerala via the Arabian Sea.

I read in one of The Watchtower magazines some years ago that an apostle could have easily taken a trade ship to reach India or even further southeast to Thailand, Cambodia, Sumatra, and Java. Jesus' disciples were commissioned to preach the good news to the most distant parts of the earth and later in his epistle to the Colossians Paul mentions that the good news was preached in all creation under then heaven.

This discovery bolsters the claims by both Cochin Jews and Saint Thomas Christians, however, only the apostle knows if he ever visited India.

Sunday, January 27, 2013

Energy Efficient Ethernet - Performance Analysis

N.B: I am posting by revising something I wrote for academic purposes. So it doesn't look like a blog article.

Energy Efficient Ethernet was a recent development in the field of computer networks that aims at minimizing the use of energy over networks. The idea for saving energy in communication systems was proposed as early as 2003 and its implementation in Ethernet links was officially made as a standard by the IEEE 802.3az task force. It is estimated that the internet core is consuming about 6 TWh of power each year and it keeps growing. One of the major power consumption is in Ethernet links. Since links can be physically long significant power would be needed to transmit information through the wires. IEEE standard defines a low power mode for idle links and thereby encourages saving energy.

Description of IEEE standard


EEE concept is described in figure (1) as seen in the Reviriego et al. 2009. The link is made active when a packet arrives and when no packets are left link enters into a low power mode. Periodically link is made active for a short time to make sure that it is working. This is denoted as a refresh cycle in the figure. Table (1) shows the proposed mean sleep time, wake-up time from Reviriego et al 2009.

Simulation experiments

Simulation of EEE was done using the CSIM. CSIM is a simulation library from Mesquisite software. It provides the facility for simulating queues. It is believed that the arrival of packets in Ethernet networks follows an exponential distribution and therefore EEE can be simulated as a Poisson process. Coincidentally packet arrivals and leaving on Ethernet links can be modeled as an M/M/1 queue. The service center would be link and queue will be packets arrived on the link. The simulation was done with 5000 packets each for 100Mbps, 1Gbps, and 10 Gbps. Energy consumption for the link was calculated using the following known formula.

= Plow power  · (1 − load) + Pactive · load

 Plow power is the power consumed in low power mode and Pactive  is the power consumed when the link is active. The load was increased from 0 to 100 at intervals of 5. It is assumed that both forward and backward packet transfer between the links are independent of each other. I also neglected the refresh cycle since it has little effect on performance. Further bulk arrivals were simulated using a geometric distribution with their means equivalent to the desired burst length. In this experiment, I used mean burst lengths of 2, 5, and 10 to find its effect on power consumption. Finally, I did experiments on real-world packet traces collected from a personal computer. Trace files used in this experiment were collected from a 100 Mbps Ethernet link. Trace files were collected when the user did typical browsing, downloading, and surfing on the internet.

Simulation Results


Results of the simulation on the regular EEE model are plotted in the graphs shown in figures (2), (3), and (5).


Results for the simulation on regular EEE were as expected. For burst arrivals, we notice that the performance is improved when the burst length is increased. Table II shows results for real-world packet trace analysis.








Results Analysis


Graphs for regular EEE at various loads show that performance is as expected. Energy consumption is proportional to the traffic of the packets as inferred from results. In 100Mbps, results are close to the proportional (ideal) case. However, in 1Gbps and 10 Gbps links, results are not good especially when traffic is high. It appears that the link is spending more time sleeping and waking up at higher traffic.

When packets appear as burst, performance is improved as expected. This is because the link is made to wake up and sleep only for the whole burst packet length. More the burst arrivals, more the performance getting close to the ideal case.

For real-world data, power consumption in EEE looks very low when compared to that of normal Ethernet. This might be because the packet arrival rate in the real world is higher than that of simulation models and hence link is in sleep most of the time.

Enhancing EEE

Improving EEE using predictive packet arrival


From our results, we see that the performance is affected in high-speed links when the packets arrive at high speed because the link would be spending more time sleeping and waking up. To overcome this issue I propose to make use of a predictive sleep method in which we sleep only if the queue is empty and mean arrival delay till the last packet is greater than sleep time. By doing so we could overcome the overhead issue due to continuous sleep and wake up in high-speed networks; however, we would be incurring a penalty if the prediction was wrong. If a packet did not arrive within the mean delay time we would need to sleep. Therefore penalty for a failed prediction, in that case, would be

Penalty = Mean packet arrival delay + TS

However, before making any judgments it is better to analyze the proposed model using simulation.

Simulation experiments


Experiments were conducted for the proposed enhancement method using CSIM Software. When each packet is leaving the system we check if the queue is empty. If the queue is empty we next verify that the mean delay for past packet arrivals is less than sleep time. If that is the case then we continue without sleeping, otherwise, we would sleep. If a packet arrives before the predicted mean delay we gain a power loss for the time equivalent to the difference between sleep time and mean packet delay time. If a packet did not arrive before the predicted mean delay time we incur the penalty described above. 

Simulation Results


The result of the proposed simulation model is shown in Figures (8), (9) & (10).






Result Analysis

The simulation results of the proposed model show that it could improve the performance without any packet loss. It also shows that the proposed method would work better for 100Mbps. The graph gets skewed toward the ideal case. Notice that a slight variation could produce increased cost benefits, and therefore this method looks better than the original proposal theoretically. There is no packet loss in this suggested improvement.

Summary

In this post, we reproduced the results of the IEEE simulation. We found that when burst arrivals are high performance in EEE is enhanced. It is also noteworthy that given the round trip time on typical internet servers is in milliseconds, the small delay in terms of microseconds in the Ethernet links is negligible when compared with the significant economic benefit. We also proposed a method to improve the performance of EEE without packet loss. However, we need more testing of the proposed system using real data before assuring its enhanced performance.


Wednesday, November 7, 2012

Edge and circle detection

Edge detection is an important application of Image processing. As the name indicates the idea is to detect edges in an input image and to highlight them using image processing algorithms. Different methods exist today to detect edges and the most commonly used algorithm is Sobel edge detection. Sobel edge detection is a direct application of differential calculus. Circle detection is an extension of edge detection in which we aim to find circle-like edges in the input image. Hough transform is an important geometric method to find circles from edges in an image. In this article, we will discuss both the concepts and their implementation, both in gray-scale and color images.

Edge detection

As we know a digitized image is represented in a computer as an array of two-dimensional pixels. A pixel is the smallest unit inside an image that can be uniquely captured using the camera. The number of pixels in an image depends on the resolution capacity of the camera. In a grayscale image, each pixel corresponds to the intensity level in that particular pixel and its value ranges from zero to 255. In color images, each pixel has red, green, and blue color levels with values ranging from zero to 255. Theoretically, a mixture of these three colors can generate any visually identifiable colors of human perception.

In edge detection, our aim is to identify portions of the image where information is densely populated. This means we are interested in identifying those pixels which form edges in an image. Edges in the image are identified by comparing them with the pixel intensity of neighboring pixels. Larger the difference or variation in brightness of pixel values, the larger the likelihood that it is an edge pixel. Therefore our interest is to identify those pixels which significantly differ from their neighboring pixels. 

The application of calculus comes into play here. We know that calculus is the study of change just like geometry is the study of shapes. Assuming that the pixel values in an image form a discrete function, our aim is to find the points in the discrete function whose slope is higher. Since an image is a 2-D function, operators describing edges can be expressed by using partial differential equations. The points that lie on an edge can be detected by detecting the local maxima or minima of the first derivative or by detecting zero-crossing of the second derivative. The idea is described in figure (1) for 1-D analysis. However, since noise in an image often forms pseudo-edges we have to pre-process the image. Therefore edge detection can be described in four steps as below.

(a)   Smoothing – to reduce noise without destroying true edges
(b)   Enhancement – improve the quality of the edges (eg. by improving sharpness)
(c)   Detection: find the edge pixels
(d)   Localization: find the exact location of the edge. (eg. linking edges together)





Figure (1) - Idea of edge detection in 1-D intensity signal function. Changes in edge can be detected using local maxima or minima of the first derivative or using the zero-crossing in the second derivative. (Source here)


The derivative of a 1-D signal can be computed by approximating the derivative by finite differences. 

Therefore








Mask for 1D signal: [-1 0 1] (centered about x)

Computing the second derivative gives,









Mask for 1-D signal using second derivative: [1 -2 1] (centered about x)

Based on the 1-D theoretical analysis, the same idea can be extended to two-dimensional pixel planes, and one such extension is known as the Sobel operator. The Sobel operator performs an accurate approximation to calculate the derivative of a two-dimensional image by computing the spatial gradient measurement of an image. Sobel detector uses a pair of 3 x 3 convolution masks, one for x-direction and the other for y-direction. Sobel operator for a two-dimensional image is as follows and it slides over the image.

Figure (2) – Sobel operator for edge detection in images.

The magnitude of the gradient is calculated using the resultant formula:

The direction is calculated by using the inverse tangent of the gradients in each direction.
















.
Figure (3) – Gradient edge and direction (source)

Some of the results of applying the Sobel operator in grayscale images and color images are shown below. In color images, we compute the intensity and use it for edge detection.

Intensity  I = (red + green + blue) / 3

After computing the edges, thresholding is applied to highlight edges that are highly likely. Again we can highlight those edges which are in a particular direction by thresholding edge intensity image using computed direction information.


Figure (4) Original Image, Edge image, Thresholded edge image and direction thresholded edge image (clockwise). ROI (x,y,sx,sy) = (10,10,450,620), threshold value = 80 and direction threshold value = 80 to 90 degrees.


Figure (5) Original Image, Edge image, Thresholded edge image and direction thresholded edge image. The ROI (x,y,sx,sy) = (10,10,450,620), threshold value = 80 and direction threshold value = 70 +- 10  degrees.



Figure (6) Original Image, Edge image, Thresholded edge image and direction thresholded edge image. The ROI (x,y,sx,sy) = (10,10,550,550), threshold value = 80 and direction threshold value = 45 +- 10 degrees.

Circle detection using Hough transform

Circle detection in image processing is done using Hough transform. Hough transform is a feature extraction technique to find imperfect instances of objects within a certain class or shape. This is done by parameterization and then voting the parameter space to find local maxima. First, we compute the edges of the image using edge detection. Then we threshold the edge image so that we can find significant edges. Now we have to find those edges which form a circle. Note that after edge detection circumference of the circles might not be connected clearly. So we apply Hough transform.

A circle can be described completely with three pieces of information: the center (a, b) and the radius R.

x = a + Rcosθ
y = b + Rsinθ

When the θ varies from 0 to 360, a complete circle of radius R is generated. We note that for a circle the parameters (a, b, R) are constant. In the parameter space, we plot the coordinates with (a, b) boundary equivalent to the set of all possible centers in a given image where θ ranges from 0 to 360. For each edge point that correspond to (x, y, R) of a particular circle in real space we draw the sphere in the corresponding (a, b, R) parameter space. If we are looking for circles of a particular radius R then we have a 2D parameter space. 


Figure (7) – Each point in the geometric space (left) generates a circle in parameter space (right). The circles in the parameter space intersect at (a,b) the center of the circle in geometric space. (source)

Rearranging the equations we get

a = x1 – Rcosθ
b = y1 – Rsinθ

After plotting the circles in parameter space, we will note that the points at which circles in parameter space intersect correspond to the center of the circle in real space. To find circles that are more likely true we compute intersections that have a high density. This is done by sampling the parameter space with a suitable bin size. Once we compute the local maxima we highlight the circle in the original space. Some results for both greyscale and color images are shown below.


Figure (8) Original Image, Edge image, Thresholded edge image, PSpace image and Resulted circle. The ROI (x,y,sx,sy) = (10,10,300,300), threshold value = 80 and radius = 33 px.




Figure (10) Original Image, Edge image, Thresholded edge image, PSpace image and Resulted circle. The ROIs (x,y,sx,sy) = (110 10 200 200)(110 280 200 200), threshold value = 80 and radius = 90 px.



Figure (11) Original Image, Edge image, Thresholded edge image, PSpace image and Resulted circles. The ROIs (x,y,sx,sy) = (180 220 80 80) (180 320 80 80), threshold value = 80 and radius = 11 px.


I have included sample code in c++ for edge detection and Hough transform. Code for classes ROI, Images are excluded.

Thursday, October 25, 2012

Histogram Equalization

A histogram is a graphical representation of the tonal values of an image. In a greyscale image, we have only one channel, and its value range from 0 to 255. Based on the number of pixels falling under a particular tonal value we plot the histogram graph. 

Grey histogram Equalization

In Grey histogram equalization we enhance the contrast of images by using usable pixel values in the image to the close contrast values of the display device. This is accomplished by spreading out the most frequent intensity values to the neighboring intensities. First, we compute the cumulative distributive function of the histogram. Then we use the general histogram formula to accomplish this.
The general histogram equalization formula is:

Where cdfmin is the minimum value of the cumulative distribution function, M × N gives the image's number of pixels and L is the number of grey levels used. Some sample results are shown below. Note that equalization is done within the two regions of interest.

(a)   Original Image

(b)   Histogram for ROI 1 before and after equalization ( x = 10, y = 10, sx = 300, sy = 300)



(c)    Histogram for ROI 2 before and after equalization ( x =315, y =315, sx = 400, sy = 400)

(d) Result - equalized image



Color Histogram Generation (RGB)

In color images, we have three channels namely red, green and blue. Therefore in order to generate the histograms, we apply the same principle for greyscale images separately for each channel.

Color Histogram Equalization (RGB)

In color histogram normalization we apply the same method used for grey-scale equalization for each of the three channels separately. The results are shown below.

(a)   Original Image
(b) Histogram for ROI 1 – Before and after equalization - RGB ( x = 10, y = 10, sx = 300, sy = 300)

(c)   Result - equalized image (all channels together)

(d)   Equalization separately - Original and  RGB channels respectively (Clockwise)



               

HSI histogram generation

HSI is a color model which is more intuitive and perceptually relevant to co-ordinate space. It has wide applications in the field of computer graphics and vision. Like RGB it has three channels namely Hue (H), Saturation(S), and Intensity (I). Hue falls from 0 to 360 degrees, and the other two fall from 0 to 1. For the sake of calculations, we make saturation fall between 0 to 99 and Intensity fall from 0 to 255 respectively. For HSI histogram generation we need to convert the RGB color model to HSI. We then generate a histogram for the three channels separately. The formula for HSI to RGB and from RGB to HSI is below from the Gonzales and Woods text.


HSI histogram equalization

After generating HSI histogram we then compute the equalized histogram from it. For that, we make use of the same histogram formula we used before. After equalization, we then convert it back to RGB image for display. The resulted images are shown below.

(a)   HSI histogram for I channel – Before and after equalization (x = 10, y =10, sx = 300, sy = 300)
(b)    HSI equalization (original and I channel respectively)


Program

Some of the functions I used to do the above operations in C++ are in Git here. Note that the custom class Image and ROI are not included here. However, this code is enough for explaining the main logic.