# How to keep track of where each measurement originates from?

1 view (last 30 days)
Goncalo Costa on 14 Jul 2021
Answered: Prachi Kulkarni on 11 Aug 2021
When creating a pattern/mask for single-pixel imaging of a picture, I use a different delta function for each measurement, and this is all done withing a for loop as follows:
img = double(im2gray(picture)) %grayscale of n pixel image , read here as picture
for i = 1:n^2
delta = zeros(n,n); %delta is nxn matrix where a single element is 1.
delta(i) = 1; % This element changes with each loop.
B(i) = sum(img.*A, 'All'); %light coming through
end
How do I keep track of where each measurement comes from. ie, which delta function corresponds to a measurement [1].
The code is intended to be applied to the use of PCA to the data (which I am still uncertain as how to do) to decrease the number of measurements needed to analyse an image.
##### 2 CommentsShowHide 1 older comment
Goncalo Costa on 21 Jul 2021
sorry that was a silly mistake when simplifying the code for the question

Prachi Kulkarni on 11 Aug 2021
Hi,
The index variable i itself is an indicator of which delta function corresponds to which measurement.
For example, for the 10th measurement B(10), the delta function can be regenerated whenever required as-
delta = zeros(n,n);
delta(10) = 1;
Alternatively, if you want to store all the delta functions (although it may not be memory-efficient), you can rewrite your code as-
img = double(im2gray(picture)); % grayscale of n pixel image , read here as picture
delta = zeros(n,n,n^2); % collection of all delta functions
for i = 1:n^2
deltaSingle = zeros(n,n); % delta is nxn matrix where a single element is 1.
deltaSingle(i) = 1; % this element changes with each loop
delta(:,:,i) = deltaSingle; % placing individual delta in the collection of delta functions
end
A = real(ifft2(delta)); % mask created for all delta functions simultaneously
B = squeeze(sum(img.*A, [1 2]))'; % light coming through computed for delta functions simultaneously