An optical illusion (also called a visual illusion) is an illusion caused by the visual system and characterized by a visual percept that (loosely said) appears to differ from reality. Illusions come in a wide variety; their categorization is difficult because the underlying cause is often not clear but a classification   proposed by Richard Gregory is useful as an orientation. According to that, there are three main classes: physical, physiological, and cognitive illusions, and in each class there are four kinds: Ambiguities, distortions, paradoxes, and fictions. A classical example for a physical distortion would be the apparent bending of a stick half immerged in water; an example for a physiological paradox is the motion aftereffect (where despite movement position remains unchanged). An example for a physiological fiction is an afterimage. Three typical cognitive distortions are the Ponzo, Poggendorff, and Müller-Lyer illusion. Physical illusions are caused by the physical environment, e.g. by the optical properties of water. Physiological illusions arise in the eye or the visual pathway, e.g. from the effects of excessive stimulation of a specific receptor type. Cognitive visual illusions are the result of unconscious inferences and are perhaps those most widely known.
Pathological visual illusions arise from pathological changes in the physiological visual perception mechanisms causing the aforementioned types of illusions; they are discussed e.g. under visual hallucinations.
A familiar phenomenon and example for a physical visual illusion is when mountains appear to be much nearer in clear weather with low humidity (Foehn) than they are. This is because haze is a cue for depth perception for far-away objects (Aerial perspective).
The classical example of a physical illusion is when a stick that is half immerged in water appears bent. This phenomenon has already been discussed by Ptolemy (ca. 150)  and was often a prototypical example for an illusion.
Physiological illusions, such as the afterimages following bright lights, or adapting stimuli of excessively longer alternating patterns (contingent perceptual aftereffect), are presumed to be the effects on the eyes or brain of excessive stimulation or interaction with contextual or competing stimuli of a specific type—brightness, color, position, tile, size, movement, etc. The theory is that a stimulus follows its individual dedicated neural path in the early stages of visual processing, and that intense or repetitive activity in that or interaction with active adjoining channels cause a physiological imbalance that alters perception.
The Hermann grid illusion and Mach bands are two illusions that are best explained using a biological approach. Lateral inhibition, where in the receptive field of the retina light and dark receptors compete with one another to become active, has been used to explain why we see bands of increased brightness at the edge of a color difference when viewing Mach bands. Once a receptor is active, it inhibits adjacent receptors. This inhibition creates contrast, highlighting edges. In the Hermann grid illusion the gray spots appear at the intersection because of the inhibitory response which occurs as a result of the increased dark surround. Lateral inhibition has also been used to explain the Hermann grid illusion, but this has been disproved.      More recent empirical approaches to optical illusions have had some success in explaining optical phenomena with which theories based on lateral inhibition have struggled.
Cognitive illusions are assumed to arise by interaction with assumptions about the world, leading to "unconscious inferences", an idea first suggested in the 19th century by the German physicist and physician Hermann Helmholtz. Cognitive illusions are commonly divided into ambiguous illusions, distorting illusions, paradox illusions, or fiction illusions.
To make sense of the world it is necessary to organize incoming sensations into information which is meaningful. Gestalt psychologists believe one way this is done is by perceiving individual sensory stimuli as a meaningful whole. Gestalt organization can be used to explain many illusions including the rabbit–duck illusion where the image as a whole switches back and forth from being a duck then being a rabbit and why in the figure–ground illusion the figure and ground are reversible.
In addition, Gestalt theory can be used to explain the illusory contours in the Kanizsa's Triangle. A floating white triangle, which does not exist, is seen. The brain has a need to see familiar simple objects and has a tendency to create a "whole" image from individual elements. Gestalt means "form" or "shape" in German. However, another explanation of the Kanizsa's Triangle is based in evolutionary psychology and the fact that in order to survive it was important to see form and edges. The use of perceptual organization to create meaning out of stimuli is the principle behind other well-known illusions including impossible objects. Our brain makes sense of shapes and symbols putting them together like a jigsaw puzzle, formulating that which isn't there to that which is believable.
The Gestalt principles of perception govern the way we group different objects. Good form is where the perceptual system tries to fill in the blanks in order to see simple objects rather than complex objects. Continuity is where the perceptual system tries to disambiguate which segments fit together into continuous lines. Proximity is where objects that are close together are associated. Similarity is where objects that are similar are seen as associated. Some of these elements have been successfully incorporated into quantitative models involving optimal estimation or Bayesian inference. 
The double-anchoring theory, a popular but recent theory of lightness illusions, states that any region belongs to one or more frameworks, created by Gestalt grouping principles, and within each framework is independently anchored to both the highest luminance and the surround luminance. A spot's lightness is determined by the average of the values computed in each framework.
Illusions can be based on an individual's ability to see in three dimensions even though the image hitting the retina is only two dimensional. The Ponzo illusion is an example of an illusion which uses monocular cues of depth perception to fool the eye. But even with two dimensional images, the brain exaggerates vertical distances when compared with horizontal distances, as in the vertical-horizontal illusion where the two lines are exactly the same length.
In the Ponzo illusion the converging parallel lines tell the brain that the image higher in the visual field is farther away therefore the brain perceives the image to be larger, although the two images hitting the retina are the same size. The optical illusion seen in a diorama/false perspective also exploits assumptions based on monocular cues of depth perception. The M.C. Escher painting Waterfall exploits rules of depth and proximity and our understanding of the physical world to create an illusion. Like depth perception, motion perception is responsible for a number of sensory illusions. Film animation is based on the illusion that the brain perceives a series of slightly varied images produced in rapid succession as a moving picture. Likewise, when we are moving, as we would be while riding in a vehicle, stable surrounding objects may appear to move. We may also perceive a large object, like an airplane, to move more slowly than smaller objects, like a car, although the larger object is actually moving faster. The phi phenomenon is yet another example of how the brain perceives motion, which is most often created by blinking lights in close succession.
The ambiguity of direction of motion due to lack of visual references for depth is shown in the spinning dancer illusion. The spinning dancer appears to be moving clockwise or counterclockwise depending on spontaneous activity in the brain where perception is subjective. Recent studies show on the fMRI that there are spontaneous fluctuations in cortical activity while watching this illusion, particularly the parietal lobe, because it is involved in perceiving movement.
Perceptual constancies are sources of illusions. Color constancy and brightness constancy are responsible for the fact that a familiar object will appear the same color regardless of the amount of light or color of light reflecting from it. An illusion of color difference or luminosity difference can be created when the luminosity or color of the area surrounding an unfamiliar object is changed. The luminosity of the object will appear brighter against a black field (that reflects less light) compared to a white field, even though the object itself did not change in luminosity. Similarly, the eye will compensate for color contrast depending on the color cast of the surrounding area.
In addition to the Gestalt principles of perception, water-color illusions contribute to the formation of optical illusions. Water-color illusions consist of object-hole effects and coloration. Object-hole effects occur when boundaries are prominent where there is a figure and background with a hole that is 3D volumetric in appearance. Coloration consists of an assimilation of color radiating from a thin-colored edge lining a darker chromatic contour. The water-color illusion describes how the human mind perceives the wholeness of an object such as top-down processing. Thus, contextual factors play into perceiving the brightness of an object.
Just as it perceives color and brightness constancies, the brain has the ability to understand familiar objects as having a consistent shape or size. For example, a door is perceived as rectangle regardless of how the image may change on the retina as the door is opened and closed. Unfamiliar objects, however, do not always follow the rules of shape constancy and may change when the perspective is changed. The Shepard illusion of the changing table is an example of an illusion based on distortions in shape constancy.
Researcher Mark Changizi of Rensselaer Polytechnic Institute in New York has a more imaginative take on optical illusions, saying that they are due to a neural lag which most humans experience while awake. When light hits the retina, about one-tenth of a second goes by before the brain translates the signal into a visual perception of the world. Scientists have known of the lag, yet they have debated how humans compensate, with some proposing that our motor system somehow modifies our movements to offset the delay.
Changizi asserts that the human visual system has evolved to compensate for neural delays by generating images of what will occur one-tenth of a second into the future. This foresight enables humans to react to events in the present, enabling humans to perform reflexive acts like catching a fly ball and to maneuver smoothly through a crowd. In an interview with ABC Changizi said, "Illusions occur when our brains attempt to perceive the future, and those perceptions don't match reality." For example, an illusion called the Hering illusion looks like bicycle spokes around a central point, with vertical lines on either side of this central, so-called vanishing point.
The illusion tricks us into thinking we are looking at a perspective picture, and thus according to Changizi, switches on our future-seeing abilities. Since we aren't actually moving and the figure is static, we misperceive the straight lines as curved ones.
Evolution has seen to it that geometric drawings like this elicit in us premonitions of the near future. The converging lines toward a vanishing point (the spokes) are cues that trick our brains into thinking we are moving forward—as we would in the real world, where the door frame (a pair of vertical lines) seems to bow out as we move through it—and we try to perceive what that world will look like in the next instant.
A pathological visual illusion is a distortion of a real external stimulus and are often diffuse and persistent. Pathological visual illusions usually occur throughout the visual field, suggesting global excitability or sensitivity alterations. Alternatively visual hallucination is the perception of an external visual stimulus where none exists. Visual hallucinations are often from focal dysfunction and are usually transient.
Types of visual illusions include oscillopsia, halos around objects, illusory palinopsia (visual trailing, light streaking, prolonged indistinct afterimages), akinetopsia, visual snow, micropsia, macropsia, teleopsia, pelopsia, Alice in Wonderland syndrome, metamorphopsia, dyschromatopsia, intense glare, blue field entoptic phenomenon, and purkinje trees.
These symptoms may indicate an underlying disease state and necessitate seeing a medical practitioner. Etiologies associated with pathological visual illusions include multiple types of ocular disease, migraines, hallucinogen persisting perception disorder, head trauma, and prescription drugs. If a medical work-up does not reveal a cause of the pathological visual illusions, the idiopathic visual disturbances could be analogous to the altered excitability state seen in visual aura with no migraine headache. If the visual illusions are diffuse and persistent, they often affect the patient's quality of life. These symptoms are often refractory to treatment and may be caused by any of the aforementioned etiologes, but are often idiopathic. There is no standard treatment for these visual disturbances.
There are a variety of different types of optical illusions. Many are included in the following list.
Artists who have worked with optical illusions include M. C. Escher, Bridget Riley, Salvador Dalí, Giuseppe Arcimboldo, Patrick Bokanowski, Marcel Duchamp, Jasper Johns, Oscar Reutersvärd, Victor Vasarely and Charles Allan Gilbert. Contemporary artists who have experimented with illusions include Jonty Hurwitz, Sandro del Prete, Octavio Ocampo, Dick Termes, Shigeo Fukuda, Patrick Hughes, István Orosz, Rob Gonsalves, Gianni A. Sarcone, Ben Heine and Akiyoshi Kitaoka. Optical illusion is also used in film by the technique of forced perspective.
Op art is a style of art that uses optical illusions to create an impression of movement, or hidden images and patterns. Trompe-l'œil uses realistic imagery to create the optical illusion that depicted objects exist in three dimensions.
The hypothesis claims that visual illusions occur because the neural circuitry in our visual system evolves, by neural learning, to a system that makes very efficient interpretations of usual 3D scenes based in the emergence of simplified models in our brain that speed up the interpretation process but give rise to optical illusions in unusual situations. In this sense, the cognitive processes hypothesis can be considered a framework for an understanding of optical illusions as the signature of the empirical statistical way vision has evolved to solve the inverse problem.
Research indicates that 3D vision capabilities emerge and are learned jointly with the planning of movements. After a long process of learning, an internal representation of the world emerges that is well-adjusted to the perceived data coming from closer objects. The representation of distant objects near the horizon is less "adequate". In fact, it is not only the Moon that seems larger when we perceive it near the horizon. In a photo of a distant scene, all distant objects are perceived as smaller than when we observe them directly using our vision.
The retinal image is the main source driving vision but what we see is a "virtual" 3D representation of the scene in front of us. We don't see a physical image of the world; we see objects, and the physical world is not itself separated into objects. We see it according to the way our brain organizes it. The names, colours, usual shapes and other information about the things we see pop up instantaneously from our neural circuitry and influence the representation of the scene. We "see" the most relevant information about the elements of the best 3D image that our neural networks can produce. The illusions arise when the "judgments" implied in the unconscious analysis of the scene are in conflict with reasoned considerations about it.