How to keep track of where each measurement originates from?

조회 수: 1 (최근 30일)
Goncalo Costa
Goncalo Costa 2021년 7월 14일
답변: Prachi Kulkarni 2021년 8월 11일
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
Walter Roberson
Walter Roberson 2021년 7월 16일
You do not use A after you compute it, but you use P?
Goncalo Costa
Goncalo Costa 2021년 7월 21일
sorry that was a silly mistake when simplifying the code for the question

댓글을 달려면 로그인하십시오.

답변 (1개)

Prachi Kulkarni
Prachi Kulkarni 2021년 8월 11일
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