Making an animation of pixels of same value appear in an image

5 views (last 30 days)
Romanus Hutchins
Romanus Hutchins on 3 Dec 2021
Edited: DGM on 3 Dec 2021
I am trying to make an animation in matlab where pixels of the same value appear at once. For example, if I have a gray image with pixels ranging with values between 0 and 255, I want to scan the image so that all of the pixels with intensity 100 apear at the same time, pixels 101 appear next, and so on.
I've already made a code using the deal function where I make the pixels appear one at a time by their index. Is there a way I can scan the pixels by pixel value using the deal function, or will I have to do something else?
I've insert the first code below as an example
close all
I = imread('supe1.jpg');
I2 = im2double(I);
I3 = rgb2gray(I2);
% imshow(gry)
I4= imresize(I3, [50, 50]);
long = length(I4(:));
% making column vector of supes
% example matrix
exam = ones(50,50);
for k = 1:long
[I4(k) , exam(k)] = deal(exam(k), I4(k));
movieVector(k) = getframe;
% figure(2)
% imshow(bizzaro)
%Create a VideoWriter object and set properties
myWriter = VideoWriter('Superman3', 'MPEG-4'); %create an .avi file
% myWriter = VideoWriter('curve','MPEG-4'); %create an .mp4 file
myWriter.FrameRate = 20;
%Open the VideoWriter object, write the movie, and close the file
writeVideo(myWriter, movieVector);

Answers (1)

DGM on 3 Dec 2021
Edited: DGM on 3 Dec 2021
Don't do this. Displays are for viewing. You're basically taking a screenshot of the image. If you want to save an image, just save the image. If you're overlaying plots or something on top of it, that might be a different story, but for plain images, this isn't needed.
movieVector(k) = getframe;
Don't need deal() or any of that. You'll have to set up the video settings as you want.
A = imread('cameraman.tif');
v = VideoWriter('glanim.avi');
for k = 0:255
thisframe = A;
thisframe(thisframe>k) = 0;


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by