text:
# How to do logarithmic shading with TikZ?

Using TikZ, the shade option is very convenient to produce color shadings, but it produces only linear color gradients. Is it possible to obtain other transitions, and especially a logarithmic one?

Thanks!

# Edit:

Here is an example for the linear case:

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\shade[left color=black, right color=white] (0,0) rectangle (10,1);
\end{tikzpicture}

\end{document}

• You can with \pgfdeclarefunctionalshading. Check the manual or tex.stackexchange.com/questions/54193/… for examples. – percusse Apr 10 '15 at 9:54
• Thank you @percusse, I am pretty sure this is what I need, but the code I have to put into the function is puzzling to me! Any help would be appreciated. – Tobard Apr 10 '15 at 10:20
• Can you include a MWE and the details about the shading direction etc. ? Then we can look at it together. – percusse Apr 10 '15 at 10:30
• I have added a MWE. I would like something very simple : a horizontal band changing from black to white with a logarithmic progression. Thanks. – Tobard Apr 10 '15 at 11:42

Here are some examples.

• R=G=B=x
• R=G=B=x²
• R=G=B=√x
• R=G=B=log(1+x)
• R=G=B=log(1+9x)
• R=G=B= ... well ...

\documentclass{article}
\usepackage[a3paper]{geometry}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\fill(-11,0)|-(0,-2)|-(11,2)|-cycle;
\end{tikzpicture}

pop 50 div .5 sub % u
dup dup % u u u
}
\begin{tikzpicture}
\fill(-11,0)|-(0,-2)|-(11,2)|-cycle;
\end{tikzpicture}

pop 50 div .5 sub % u
dup mul % u²
dup dup % u² u² u²
}
\begin{tikzpicture}
\fill(-11,0)|-(0,-2)|-(11,2)|-cycle;
\end{tikzpicture}

pop 50 div .5 sub % u
sqrt % √u
dup dup % √u √u √u
}
\begin{tikzpicture}
\fill(-11,0)|-(0,-2)|-(11,2)|-cycle;
\end{tikzpicture}

pop 50 div .5 sub % u
dup dup % ㏒(1+u) ㏒(1+u) ㏒(1+u)
}
\begin{tikzpicture}
\fill(-11,0)|-(0,-2)|-(11,2)|-cycle;
\end{tikzpicture}

pop 50 div .5 sub % u
9 mul 1 add log % ㏒(1+9u)
dup dup % ㏒(1+9u) ㏒(1+9u) ㏒(1+9u)
}
\begin{tikzpicture}
\fill(-11,0)|-(0,-2)|-(11,2)|-cycle;
\end{tikzpicture}

50 div .5 sub exch % v U
50 div .5 sub 4 mul exch % 4u v
dup 1 exch sub % 4u v 1-v
2 index % 4u v (1-v) 4u
mul mul % u 4uv(1-v)
dup 1 exch sub 2 index mul mul
dup 1 exch sub 2 index mul mul
dup 1 exch sub 2 index mul mul
dup 1 exch sub 2 index mul mul
dup 1 exch sub 2 index mul mul
exch pop
}
\begin{tikzpicture}
\fill(-11,0)|-(0,-2)|-(11,2)|-cycle;
\end{tikzpicture}

\end{document}

### Remarks

• dup duplicates the topmost element.
• The dup dup at every very end is actually unnecessary.
• If you leave only a single number in the stack, PDF-renderer will treat it as the grayscale.
• If there are three, they are R, G, B respectively.
• If there are 0 or 2 or 4, 5, 6, ... I do not know.
• pop discards the topmost element.
• The pop at every very beginning throws away the y-coordinate, which is useless except the last case.
• Replacing pop by swap, you can leave the y-coordinate at the bottom alone. But then dup dup becomes necessary.
• Thank you! Could you just explain what pop mean, and why dup commands are needed? – Tobard Apr 15 '15 at 13:22


text:
## Class/Course - Engineering Entrance

### Subject - Chemistry

#### Total Number of Question/s - 3121

Just Exam provide question bank for Engineering Entrance standard. Currently number of question's are 3121. We provide this data in all format (word, excel, pdf, sql, latex form with images) to institutes for conducting online test/ examinations. Here we are providing some demo contents. Interested person may contact us at info@justexam.in

• 1. Some Basic Concepts of Chemistry - Quiz

1. A gaseous hydrocarbon gives upon combustion, 0.72 g of water and 3.08 g of CO2. The empirical formula of the hydrocarbon is:
a) C2H4
b) C3H4
c) C6H5
d) C7H8

2. The molarity of a solution obtained by mixing 750 mL of 0.5 M HCl with 250mL of 2M HCl will be
a) 0.875 M
b) 1.00 M
c) 1.75 M
d) 0.0975 M

• 2. States of Matter - Quiz

1. In a face-centered cubic lattice, atom A occupies the corner positions. If one atom of B is missing from one of the face centered points , the formula of the compounds is
a) A2B
b) AB2
c) AB
d) A2B2

2. Which one of the following statements is not true about the effect of an increase in temperature on the distribution of molecular speeds in a gas?
a) The area under the distribution curve remains the same as under the lower temperature
b) The distribution becomes broader
c) The fraction of the molecules with the most probable speed increases
d) The most probable speed increases

• 3. Atomic Structure - Quiz

1. The energy required to break one mole of Cl-Cl bonds in Cl2 is 242 kJ mol-1 . The longest wavelength of light capable of breaking a single Cl-Cl bond is
a) 594 nm
b) 640 nm
c) 700 nm
d) 494 nm

2. The ionisation enthalpy of hydrogen atom is 1.312× 106 J mol-1 . The energy required to excite the electron in the atom from n1 = 1 to n=2 is
a) 8.51×105 J mol-1
b) 6.56 × 105 J mol-1
c) 7.56 × 105 J mol-1
d) 9.84 × 105 mol-1

• 4. Chemical Bonding - Quiz

1. For which of the following molecule significant μ = 0?
(i)
(ii)
(iii)
(iv)
a) Only (i)
b) (i) and (ii)
c) Only (iii)
d) (iii) and (iv)

2. The decreasing values of bond angles from NH3 (1070) to SbH3 (910) down group-15 of the periodic table is due to
a) increasing bp-bp repulsion
b) increasing p-orbital character in sp3
c) decreasing lp-bp repulsion
d) decreasing electronegativity

• 5. Thermodynamics - Quiz

1. For a spontaneous reaction, the ΔG, equilibrium constant (K) and E0 cell will be respectively
a) -ve , > 1, -ve
b) -ve, < 1, -ve
c) +ve, > 1, -ve
d) -ve , > 1, +ve

2. Identify the correct statement regarding a spontaneous process
a) For a spontaneous process in an isolated system, the change in entropy is positive
b) Endothermic process are never spontaneous
c) Exothermic process are always spontaneous
d) Lowering of energy in the reaction process is the only criteria for spontaneity

• 6. Solutions - Quiz

1. Equal masses of methane and oxygen are mixed in an empty container at 250 C. the fraction of the total pressure exerted by oxygen is
a) $\frac{2}{3}$
b) $\frac{1}{3} \times \frac{273}{298}$
c) $\frac{1}{3}$
d) $\frac{1}{2}$

2. Equimolar solutions in the same solvent have
a) different boiling point and freezing point
b) same boiling point and same freezing point
c) same freezing point but different boiling point
d) same boiling point but different freezing point

• 7. Equilibrium - Quiz

1. The pH of a 0.1 molar solution of the acid HQ is 3. The value of the ionisation constant, Ka of the acid is
a) 3 x 10-1
b) 1 x 10-3
c) 1 x 10-5
d) 1 x 10-7

2. The conjugate base of $H_{2}PO_{4}^{-}$ is
a) $PO_{4}^{-3}$
b) P2O5
c) H3PO4
d) $HPO_{4}^{2-}$

• 8. Redox Reactions and Electrochemistry - Quiz

1. Consider the following reaction, $xMnO_{4}^{-} + yC_{2}O_{4}^{2-} + zH^{+} → xMn^{2+} + 2yCO_{2} + \frac{z}{2}H_{2}O$
The values of x,y and z in the reaction are, respectively
a) 5,2 and 16
b) 2,5 and 8
c) 2,5 and 16
d) 5,2 and 8

2. The equivalent consuctance of NaCl at concentration C and at infinite dilution are λc and λ, respectively . The correct relationship between λc and λ is given as
a) λc = λ + (B)C
b) λc = λ - (B)C
c) λc = $\lambda_{\infty } - \left (B \right )\sqrt {C}$
d) λc = $\lambda_{\infty } + \left (B \right )\sqrt {C}$

• 9. Chemical Kinetics and Surface Chemistry - Quiz

1. The rate law for a reaction between the substances A and B is given by rate = k[A]n[B]m. On doubling the concentration of A and halving the concentration of B, the ratio of the new rate to the earlier rate of the reacion will be as
a) $\frac{1}{2^{m + n}}$
b) (m + n)
c) (n - m )
d) 2(n-m)

2. The disperse phase in colloidal iron (III) hydroxide and colloidal gold is positively and negatively charged, respectively. Which of the following statements is not correct?
a) Coagulation in both sols can be brought about by electrophoresis
b) Mixing the sols has no effect
c) Sodium sulphate causes cosgulation in both sols
d) Magnesium chloride solution coagulation the gold sol more readily than the iron (III) hydroxide sol

• 10. Periodicity of Elements - Quiz

1. Which one of the following sets of ions represents a collection of isoelectronic species?
a) K+ , Cl-, Ca2+ , Sc3+
b) Ba2+, Sr2+, K+, S2-
c) N3-, O2-, F-, S2-
d) Li+ , Na+, Mg2+, Ca2+

2. Which of the following represents the correct order of increasing first ionization enthalpy for Ca, Ba, S, Se and Ar?
a) Ca < S < Ba < Se < Ar
b) S < Se < Ca < Ba < Ar
c) Ba < Ca < Se < S < Ar
d) Ca < Ba < S < Se < Ar

• 11. Principles and Processes of Metallurgy - Quiz

1. Cyanide process is used for the extraction of
a) barium
b) silver
c) boron
d) zinc

2. During the process of electrolytic refining of copper, some metals present as impurity settle as anode mud. These are
a) Fe and Ni
b) Ag and Au
c) Pb and Zn
d) Se and Ag

• 12. Hydrogen, s and p-Block Elements - Quiz

1. The type hybridisation of boron in diborane is
a) sp hybridisation
b) sp2 hybridisation
c) sp3 hybridisation
d) sp3d2 hybridisation

2. One mole of magnesium nitride on reaction with an excess of water gives
a) one mole of ammonia
b) one mole of nitric acid
c) two moles of ammonia
d) two moles of nitric acid

• 13. d- and f-Block Elements and Coordination Chemistry - Quiz

1. Which of the following groups of transition metals is called coinage metals?
a) Cu,Ag,Au
b) Ru,Rh,Pd
c) Fe,Co,Ni
d) Os,Ir,Pt

2. Larger number of oxidation states are exhibited by the actinoids than those by the lanthanoids, the main reason being
a) 4d orbitals more diffused than the 5f orbitals
b) lesser energy difference between 5f and 6d than between 4f and 5d orbitals
c) more energy difference between 5f and 6d than between 4f and 5d orbitals
d) more reactive nature of the actinoids than the lanthanoides

• 14. Environmental Chemistry - Quiz

1. Identify the wrong statements in the following
a) Chlorofluorocarbons are responsible for ozone layer depletion
b) Green house effect is responsible for global warming
c) Ozone layer does not permit infrared radiation from the sun to reach the earth
d) Acid rain is mostly because of oxides of nitrogen and sulphur

2. The smog is essentially caused by the presence of
a) O2 and O3
b) O2 and N2
c) oxides of sulphur and nitrogen
d) O3 and N2

• 15. General Organic Chemistry - Quiz

1. In the following benzyl/allyl system
R-CH=CH2 or
(R is alkyl group)
decreasing order of inductive effect is
a) (CH3)3C- > (CH3)2CH - > CH3CH2-
b) CH3CH2- > (CH3)2CH - > (CH3)3C-
c) (CH3)2CH- > CH3CH2- > (CH3)3C-
d) (CH3)2C- > CH3CH2 - > (CH3)3OH-

2. Which of the following compounds is not chiral?
a) 1-chloropentane
b) 2-chloropentane
c) 1-chloro-2-methyl pentane
d) 3-chloro-2-methyl pentane

• 16. Hydrocarbons and their Halogen Derivatives - Quiz

1. The compound formed on heating chlorobenzene with chloral in the presence of concentrated sulphuric acid is
a) gammexane
b) DDT
c) freon
d) hexachloroethane

2. Which branched chain isomer of the hydrocarbon with molecular mass 72u gives only isomer of mono substituted alkyl halide.?
a) Tertiary butyl chloride
b) Neopentane
c) Isohexane
d) Neohexane

• 17. Organic Compounds Containing Oxygen - Quiz

1. Phenyl magnesium bromide reacts with methanol to give
a) a mixture of anisol and Mg(OH)Br
b) a mixture of benzene and Mg(OMe)Br
c) a mixture of toulene and Mg(OH)Be
d) a mixture of phenol and Mg(Me)Br

2. Phenol is heated with a solution of mixture of KBr and KBrO3 . The major product obtained in the above reaction is
a) 2-bromophenol
b) 3-bromophenol
c) 4-bromophenol
d) 2,4,6-tribromophenol

• 18. Organic Compounds Containing Nitrogen - Quiz

1. Which one of the following is the strongest base in aqueous solution?
a) Trimethylamine
b) Aniline
c) Dimethylamine
d) Methylamine

2. On heating benzyl amine with chloroform and ethanolic KOH, product obtained by
a) benzyl alcohol
b) benzaldehyde
c) benzonitrile
d) benzyl isocyanide

• 19. Polymers and Biomolecules - Quiz

1. The term anomers of glucose refers to
a) isomers of glucose that differ in configuration at carbons one and four (C-1 and C-4)
b) a mixture of (D)-glucose and (L)-glucose
c) enantiomers of glucose
d) isomers of glucose that differ in configuartion at carbon one (C-1)

2. α-D(+)-glucoseand β-D-(+)-glucose are
a) conformers
b) epimers
c) anomers
d) enantiomers

• 20. Analytical Chemistry and Chemistry in Everyday Life - Quiz

1. Coordination compounds have great importance in biological systems. In this context , which of the following statements is incorrect?
a) Chlorophyll is green pigment in plant and contain calcium
b) Haemoglobin is the red pigment of blood and contains iron
c) Cyanocobalamin is vitamin B12 and contains cobalt
d) Carboxypeptidase-A is an enzyme and contains zinc

2. If Fe3+ and Cr3+ both in group III of qualitative analysis, then distinction ,can be made by
a) addition of NH4OH in the presence of NH4Cl when only Fe(OH)3 is prexipitated
b) addition of NH4OH in presence of NH4 when Ca(OH)3 and Fe(OH)3 both are precipitated and on adding Br2 walter and NaOH , Cr(OH)3 day dissolves
c) precipitate of Ce(OH)3 and Fe(OH)3 as obtained in (b) are treated with conc. HCl when only Fe(OH)3 dissolves
d) both (b) and (c)

format: plain


text:
# Rendered image shows visible “line strokes” artefacts

If I just render the default cube it will look like this:

It is rendered with color depth 16. I can see there are artefacts consisting of visible "line strokes" on some of the cube faces.

The bands seems to not go darker and darker, but alternates between light and dark, or is my eye fooled?

Why?

# Edit

Here comes a gradient created by gimp without banding, using the same computer:

• This is due to banding. If you are viewing that 16bit image on 10 or 12bit display, you shouldn't see any banding. But on 8bit display the banding is still there and you get rid of it by dithering. Basically just add noise to the image. – Jaroslav Jerryno Novotny Mar 2 '17 at 18:15
• I view the image on a modern display. – Anders Lindén Mar 2 '17 at 18:23
• Then the artefacts would not grow when I am scaling it :) – Anders Lindén Mar 2 '17 at 21:41
• After some research, I can say the viewer isn't broken. The viewer is just not displaying the image in that way I would expect in 2017 @AndersLindén. It seems to be an opengl precision issue, probably to avoid conflicts with older graphic cards or due the lack of interest implementing this properly, not sure... However, nowadys it's possible to display the image without the banding and without manually adjusting a dithering value so hopefully a developer will fix this in the near future. – p2or Mar 4 '17 at 14:44
• Also I noticed that in most cases a dithering value of 0.85 is enough to get a clean image, but then this "generated noise" is baked into the image when saving as jpg or similar, which isn't really useful in most cases. So leaving the dithering value at 0.0, rendering as exr and adding real film grain at the end of the process is the way to go (IMO). – p2or Mar 4 '17 at 14:44

The artifact is called color banding and is a common occurence in computer graphics. (Most) computer monitors only have a range of 8 bit per channel. The human eye can differentiate a much greater resolution of light values, especially in dark tones.
See this less specific, but informative article.

Hence, color banding is especially visible in dark gradients. An image with a depth of 12 bit or more viewed on the according viewing device would have practically no visible banding.

Although a bit depth of 16 and higher are today's standard in computer graphics such as 32-bit floating points, which have no banding in theory (most) monitors remain in 8-bit color mode.

Most image related software "solves" this issue by adding noise to the image. This process is called dithering.

Different software manage this in different ways.

• The gradient tool in Photoshop has a dither option.

• Nuke dithers gradients dynamically in the output viewer.

• Blender has a dither slider, this allows the user to control the dithering amount manually.

By default, Blender's dither value is at $$0$$. That's why you can see the color banding even if the image is rendering in 32-bit floating points. Blender will always render images in 32-bit floating point color depth. Only when you save the image, will Blender convert it to the selected bit depth of the output format.

The image you displayed has dithering already applied. When increasing the contrast we can see the noise, which GIMP added to the gradient.

If we increase the dither property in Blender to $$1$$ and render the default group, there will be no visible banding artifacts.

Otherwise banding will show (dither value of $$0$$).

Increasing the contrast afterwards can reveal the dithering noise. (Left, dither at 1; right: dither at 0)

### When should I not use dithering?

Do not save images with applied dithering when you plan on processing them further. Save them with a high bit depth (16-bit or more). Postproduction applications can then do color operations correctly and dither the image at the last step if necessary.

Example: A color correction with applied dithering noise would change the amount of noise in some parts of the image thus resulting in uneven dither, which could possibly be visible.

### When should I use dithering?

Use dithering in the final step of production, where the product is created which has the chance to be viewed on an 8 bit display. (In other words all final image material.)


text:
Binary Line Search

 1 It seems that one thing that could be done to minimize a convex function of one variable would be to start at a point x where the gradient is negative and then check point x'. If the gradient has reversed direction, then we choose the midpoint between x,x' and continue. However, I've never seen such a method used anywhere. Does it not perform well in practice compared to ordinary gradient descent? asked 26 Oct '11, 15:41 Opt 95●2●8 accept rate: 0%

 1 Bisection search is certainly taught as a ”standard” method of line search (along with golden section search and some others that I'm forgetting at the moment). I don't know what's popular with vendors of NLP solvers. I used to favor golden section when I wrote my own code because (a) derivative computations are sometimes expensive and (b) not every convex function is differentiable; but that's just a personal preference. answered 26 Oct '11, 18:12 Paul Rubin ♦♦ 14.6k●4●12 accept rate: 19% Thanks for the answer. Are there multivariate generalization of the bisection and/or golden section methods? (26 Oct '11, 18:28) Opt Not that I know of. The closest I can come are some "hill-climbing" methods, one of which is due to Nelder and Mead and (rather confusingly) called the "simplex" algorithm. (Search using the authors' names to avoid many, many irrelevant results.) (26 Oct '11, 18:43) Paul Rubin ♦♦ Perhaps it's a matter of naming conventions, but some references like Bazaraa et al.'s Nonlinear Programming denote the derivative counterpart of binary search method as the Bisection search method. (27 Oct '11, 11:55) Ehsan ♦
 1 Bisection search usually applies to the problem of finding a root. Start with a point with positive value and a point with negative value. Take the midpoint, determine its value, and replace the endpoint with the same sign with the midpoint. If the function is continuous, you will eventually converge on a root. One could use bisection search with the derivative of the function of interest, which is essentially what Opt proposes, but I think other methods are generally considered superior. (I'd have to go back to an NLP text to recover the convergence rate proofs, but they are in any standard text.) The usual line searches for differentiable functions are based on Newton's method (which has quadratic local convergence), but modified to guarantee global convergence. Paul's suggestion is relevant for continuous functions that may not be differentiable. IIRC, Golden section search minimizes the number of function evaluations compared to other interval search techniques like midpoint. (I haven't taught NLP in a little while, so take this all with a grain of salt.) answered 26 Oct '11, 22:06 Matthew Salt... ♦ 4.7k●3●10 accept rate: 17% Once you've restricted the search to a finite interval, bisection reduces the interval 50% per iteration compared to roughly 40% with golden section. (26 Oct '11, 22:23) Paul Rubin ♦♦ So both converge linearly. But golden section reuses some function evaluations that can't be reused in bisection, so the overall number of function evaluations is smaller. That matters if function evaluations are costly. (I guess I really should look this up...) (26 Oct '11, 22:32) Matthew Salt... ♦ Required number of observation for binary search and golden section methods are given on page 355 of Bazaraa et al.'s Nonlinear Programming - Theory and Algorithms, 3rd edition. (27 Oct '11, 11:57) Ehsan ♦
 toggle preview community wiki

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "Title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

Tags:

×190