Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Octree
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Example color quantization== Taking the full list of colors of a 24-bit RGB image as point input to the Octree point decomposition implementation outlined above, the following example show the results of octree color quantization. The first image is the original (532818 distinct colors), while the second is the quantized image (184 distinct colors) using octree decomposition, with each pixel assigned the color at the center of the octree bin in which it falls. Alternatively, final colors could be chosen at the centroid of all colors in each octree bin, however this added computation has very little effect on the visual result.<ref>Bloomberg, Dan S. [http://leptonica.org/papers/colorquant.pdf "Color quantization using octrees."], 4 September 2008. Retrieved on 12 December 2014.</ref> <syntaxhighlight lang="matlab"> % Read the original RGB image Img = imread('IMG_9980.CR2'); % Extract pixels as RGB point triplets pts = reshape(Img, [], 3); % Create OcTree decomposition object using a target bin capacity OT = OcTree(pts, 'BinCapacity', ceil((size(pts, 1) / 256) * 7)); % Find which bins are "leaf nodes" on the octree object leafs = find(~ismember(1:OT.BinCount, OT.BinParents) & ... ismember(1:OT.BinCount, OT.PointBins)); % Find the central RGB location of each leaf bin binCents = mean(reshape(OT.BinBoundaries(leafs,:), [], 3, 2), 3); % Make a new "indexed" image with a color map ImgIdx = zeros(size(Img, 1), size(Img, 2)); for i = 1:length(leafs) pxNos = find(OT.PointBins==leafs(i)); ImgIdx(pxNos) = i; end ImgMap = binCents / 255; % Convert 8-bit color to MATLAB rgb values % Display the original 532818-color image and resulting 184-color image figure subplot(1, 2, 1), imshow(Img) title(sprintf('Original %d color image', size(unique(pts,'rows'), 1))) subplot(1, 2, 2), imshow(ImgIdx, ImgMap) title(sprintf('Octree-quantized %d color image', size(ImgMap, 1))) </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)