How to keep track of where each measurement originates from?

2 visualizaciones (últimos 30 días)
Goncalo Costa
Goncalo Costa el 14 de Jul. de 2021
Respondida: Prachi Kulkarni el 11 de Ag. de 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.
A = real(ifft2(delta)) %mask
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 comentarios
Walter Roberson
Walter Roberson el 16 de Jul. de 2021
You do not use A after you compute it, but you use P?
Goncalo Costa
Goncalo Costa el 21 de Jul. de 2021
sorry that was a silly mistake when simplifying the code for the question

Iniciar sesión para comentar.

Respuestas (1)

Prachi Kulkarni
Prachi Kulkarni el 11 de Ag. de 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

Community Treasure Hunt

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

Start Hunting!

Translated by