check intensity of the pixel last 10 pixel values of an image

1 view (last 30 days)
Hi, im trying to check intensity of the pixel last 10 pixel values of an image to compare to another image. If the intensity of the pixel changes either brighter or darker by a set threshold, and flag this pixel as a foreground pixel.
  4 Comments
Jan
Jan on 17 Dec 2021
The question concerns a video, not an image. Then "10 last pixels" is easier to understand.
How can we help you now? I recommend to ask a specific question concerning Matlab. Focus on one problem after the other. Post the code you have written so far.
Did you import the video already? Do you know how to find the "intensity" of a pixel?
Rik
Rik on 17 Dec 2021
Clarification posted as new question by @michael bowen:
hi i was wondering how to put a group of 10 images that are 1920 x 1080 into a matrix that is size 1920x1080x10. Im doing this to keep track of values for each pixel.
i have tried
for i = 1:10
outputFileName = sprintf('bwImage%d.jpg', i);
imdata =imread(outputFileName);
allImages{i} = imread(outputFileName);
end
but this creates and matrix size 1 x 10.
This matrix will be used to calculate the average value at each pixel location

Sign in to comment.

Answers (1)

DGM
DGM on 17 Dec 2021
Edited: DGM on 17 Dec 2021
This could be a start. It would probably be faster to do it with cell arrays, but the text suggests doing it with a simple stack on dim3.
This example uses a built-in set of microscopy images. Since there are only 10 frames in the entire set, I'm using a smaller window size for averaging.
totalframes = 10; % number of images in entire frame set
avgframes = 3; % number of frames to use for averaging
fnamept = 'AT3_1m4_%02d.tif';
threshold = 20;
% preallocate (assumes data is uint8, 1 sample per pixel)
S = imfinfo(sprintf(fnamept,1));
priorframes = zeros(S.Height,S.Width,avgframes,'uint8');
% fill queue
for k = 1:avgframes
priorframes(:,:,k) = imread(sprintf(fnamept, k));
end
% preallocate mask
fgmask = false(size(priorframes,1),size(priorframes,2),totalframes-avgframes);
% build mask set
for k = avgframes+1:totalframes
av = uint8(mean(priorframes,3));
priorframes = circshift(priorframes,[0 0 -1]);
priorframes(:,:,end) = imread(sprintf(fnamept, k));
fgmask(:,:,k-avgframes) = abs(priorframes(:,:,end)-av) > threshold;
end
montage(fgmask) % show the masks
The result is a stack of logical masks representing the FG content of each tested frame. Note that there are necessarily fewer mask frames (7) than there are total input frames (10). If you wanted the mask array to be front-padded to keep the indices matching, you can just adjust the following lines:
fgmask = false(size(priorframes,1),size(priorframes,2),totalframes);
and
fgmask(:,:,k) = abs(priorframes(:,:,end)-av) > threshold;
What you do with these masks is up to you. The text suggests to convert them to uint8, but if they're to be used for image composition, then doing so would be counterproductive.

Products

Community Treasure Hunt

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

Start Hunting!