Borrar filtros
Borrar filtros

How to get a matrix which acquires a pixel values along a spiral trajectory of Image.

1 visualización (últimos 30 días)
Hi, I'm working on compressive sensing for laser scanning applications. I want to sample the image along a continuous trajectory and get the pixel values. I'm able to get the pixel values along a continuous trajectory. In this case, a spiral trajectory. However, I don't know how to obtain the sampling matric C in y = Cx, where x is the input vector image, C is the sampling matrix which, on multiplying, gives values along the defined trajectory and y is the pixel values along that trajectory.
clear all;
clc;
%% Goal is to acuqire a pixel values along a spiral trajectory of Image (X).
% i.e y = Cx;
% where y is a m*1 measument matrix
% C is a m*N sampling matrix
% X is a N by 1 vectorized Image.
% N = n1*n2 where n1, n2 are size of the image
% Paramters for Spiral
dSpirals = 30;
nSpirals = 20;
CompresRatio = 0.4;
InputImage = imread('barbara1.png');
[height width] = size(InputImage);
N = height*width;
m = round(CompresRatio*N);
nPoints = m;
theta = linspace(0,360*nSpirals, nPoints);
% Define Spiral
x = round(((width/2)+1) +(theta/dSpirals).*cosd(theta));
y = round(((height/2)+1) +(theta/dSpirals).*sind(theta));
plot(x,y);
axis([0 width 0 height]);
grid on;
%% Measure the pixel values along the spiral trajectory
Measure = zeros(m,1);
for i = 1:m
Measure(m) = InputImage(x(i),y(i));
end
%% How to find C in y = CX where:
% y = Measure
% X = InputImageV %i.e., InputImageV = InputImage(:);
  4 comentarios
Matt J
Matt J el 29 de Jul. de 2022
Editada: Matt J el 29 de Jul. de 2022
I don't see how you'd be able to solve for x, because C is non-square. If C were square and invertible, it would be a permutation matrix. You don't need the matrix form of C to solve an equation which is just a permutation.
In any case, if you are certain that C is what you want, you will hopefully consider Accept-clicking my answer below.
Ajay Gunalan
Ajay Gunalan el 1 de Ag. de 2022
Just as an optional comment, I'll add these. I was able to reconstruct the image (X) in spite of C being a non-square matrix. Click here for the result and code. The result is not perfect. However, I'm working on it to get the optimal result.

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 29 de Jul. de 2022
sz=size(Image);
J=sub2ind(sz,x,y);
I=(1:numel(x))';
C=sparse(I,J,1);
  5 comentarios
Matt J
Matt J el 29 de Jul. de 2022
This should fix it.
sz=size(Image);
J=sub2ind(sz,x,y);
I=(1:numel(x))';
C=sparse(I,J,1,numel(x), prod(sz));
Ajay Gunalan
Ajay Gunalan el 29 de Jul. de 2022
Editada: Ajay Gunalan el 3 de Ag. de 2022
Thank you so much for solving it quickly. It solved my issue. I could have never solved this on my own. I still don't understand your solution. But it works. I will try to understand it. Once again, thanks a lot..!

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by