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

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

What does this mean: "check intensity of the pixel last 10 pixel values"?
i honestly dont know trying to make a program for Segmentation and Background Subtraction of a video and these are the steps i have to do for it
There are several different methods available for background subtraction, and we’re going to focus on a basic approach. A basic approach is to track the last 10 pixel values of each video frame. If the intensity of the pixel changes either brighter or darker by a set threshold, we will flag this pixel as a foreground pixel. In order to do this, you will need to know the dimensions of the video you will be using and create a matrix of those dimensions with a third dimension of value 10. For example, if the video you are using is 1920x1080, you will want to create a matrix of size 1920x1080x10. A matrix of this size will allow us to keep track of the last 10 values for each pixel.
Read in the first 10 frames to create a matrix that you will track the last 10 frames viewed. This matrix will be used to calculate the average value at each pixel location
What you want to do next is create a loop that will run through each of the image files that you created. In each of these iterations you will want to do the following:
a. Compare each of the pixel values (height by width) to the average value stored in the average matrix. If the absolute value of the difference is greater than some threshold (start with threshold = 20) set the value of that corresponding pixel in the newImage to be white (intensity value 255). If it’s less than the threshold you will set the value of that corresponding pixel in the newImage to be black (intensity value 0). If the pixel value is white, it is a foreground pixel, if it’s set to black, it’s a background pixel.
b. Update the average matrix by replacing the oldest image in the matrix with the current image.
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?
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)

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.

Categories

Products

Asked:

on 17 Dec 2021

Edited:

DGM
on 17 Dec 2021

Community Treasure Hunt

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

Start Hunting!