Use interp2 to transform a binary matrix with polar values to cartesian values

3 views (last 30 days)
Hi,
I have a Matrix with binary values, which shows an edge of a bscan
I want to transform this binary matrix into Cartesian values. I already have a skript which can transform polar images into cartesian but using it on binary values gets the following Error:
Error using griddedInterpolant
Sample values must be of type double or single.
My Code to transform the Matrix is the following:
function [bscanCart] = image2Cart(bscan)
% Determine size
[height,length] = size(bscan);
theta = linspace(-pi,pi,length);
rho = 1:1:height;
[THETA,RHO] = meshgrid(theta,rho);
% Determine grid for interpolation
[XCart,YCart] = meshgrid(linspace(-512, 512, 512*2), linspace(-512, 512, 512*2));
[XPol,YPol] = cart2pol(XCart,YCart);
% interpolating
bscanCart = interp2(THETA,RHO,bscan,XPol,YPol);
end
This is how the bscan looks like after the transformation

Accepted Answer

KALYAN ACHARJYA
KALYAN ACHARJYA on 1 Jul 2023
Edited: KALYAN ACHARJYA on 1 Jul 2023
bscan=rgb2gray(imread('image.png'));
result=image2Cart(double(bscan));
imshow(result);
function [bscanCart] = image2Cart(bscan)
% Determine size
[height,length] = size(bscan);
theta = linspace(-pi,pi,length);
rho = 1:1:height;
[THETA,RHO] = meshgrid(theta,rho);
% Determine grid for interpolation
[XCart,YCart] = meshgrid(linspace(-512, 512, 512*2), linspace(-512, 512, 512*2));
[XPol,YPol] = cart2pol(XCart,YCart);
% interpolating
bscanCart = interp2(THETA,RHO,bscan,XPol,YPol);
end

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!