Display the image X using its associated colormap, map, which has 220 colors.
figure
image(X)
colormap(map)
axis off
Make a movie that shows the effect of reducing the number of colors of the image. There will be eight movie frames in total. Preallocate an array of structures to store the movie frames.
F(8) = struct('cdata',[],'colormap',[]);
In a loop, reduce the number of colors in the indexed image by using the imapprox function. Use the im2frame function to convert the images into frames of a movie. The first frame is the original image with all 220 colors. The second frame has 128 colors. Each successive frame has half the number of colors. The last frame has the minimum number of colors, 2.
for j = 1:8
q = 2^(9-j);
[Y,newmap] = imapprox(X,map,q,'nodither');
F(j) = im2frame(Y,newmap);
end
To play the movie twice with a frame rate of three frames per second, use movie(F,2,3).
Truecolor image, specified as an
m-by-n-by-3 numeric array. If you
specify an image of data type double, then values must be
in the range [0, 1].
Data Types: double | uint8
Indexed image, specified as an
m-by-n matrix of integers.
Data Types: double | uint8
Colormap associated with indexed image X, specified
as a c-by-3 numeric matrix with values in the range [0,
1]. Each row of map is a three-element RGB triplet that
specifies the red, green, and blue components of a single color of the
colormap.
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window.
Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.