Azzera filtri
Azzera filtri

Cylinder unwrapping with imtransform

2 visualizzazioni (ultimi 30 giorni)
Elisa
Elisa il 18 Set 2014
Risposto: Elisa il 19 Set 2014
Hello everybody, I am trying to make the unwrapping of a photo of a cylindrical object (only one side), I applied this code I wrote:
if true
% code
I = imread('2258.jpg');
axis on
box on
imshow(I)
ndims_in = 2;
ndims_out = 2;
forward_mapping = []
f = @(x, unused) arcsin(1/x);
inverse_mapping = f;
tdata = [];
tform = maketform('custom', ndims_in, ndims_out, ...
forward_mapping, inverse_mapping, tdata);
udata = [-1 1];
vdata = [-1 1];
xdata = [-1.57 1.57];
ydata = [-1 1];
I2 = imtransform(I, tform, 'UData', udata, 'VData', vdata, ...
'XData', xdata, 'YData', ydata);
subplot(1,2,1)
imshow(I)
subplot(1,2,2)
imshow(I2)
end
but I received lots of errors: ??? Error using ==> mldivide Matrix dimensions must agree.
Error in ==> @(x,unused)arcsin(1/x)
Error in ==> maketform>inv_composite at 592 U = feval(t.tdata(i).inverse_fcn, U, t.tdata(i));
Error in ==> tform at 56 X = feval( t.(f.fwd_fcn), U, t );
Error in ==> tforminv at 68 varargout = tform('inv', nargout, varargin{:});
Error in ==> tformarray at 241 M = tforminv(G,T);
Error in ==> imtransform at 275 B = tformarray(args.A, args.tform, args.resampler, tdims_a, tdims_b, ...
Where is the error for you? How could I solve it? Thank you a lot, Phalaen
  1 Commento
Image Analyst
Image Analyst il 18 Set 2014
How about attaching '2258.jpg' so people can try your code?

Accedi per commentare.

Risposta accettata

David Young
David Young il 18 Set 2014
Modificato: David Young il 18 Set 2014
I haven't tested this, but here's a quick thought: try replacing
f = @(x, unused) arcsin(1/x);
with
f = @(x, unused) asin(1./x);
as you probably want the element-by-element division rather than the matrix inverse here.
[Edit: arcsin replaced with asin to take note of Youssef Khmou's helpful comment]

Più risposte (2)

Elisa
Elisa il 19 Set 2014
Thank you David and Youssef, with your suggestion (f = @(x, unused) asin(1./x);) matlab gave no error messages, the problem now is that, after the computation, it returns a completely black image and not the stretched image, what could the problem be? Thank you!
  1 Commento
David Young
David Young il 19 Set 2014
Hard to know - maybe if you attach the image as suggested by Image Analyst it might be possible to figure it out.

Accedi per commentare.


Elisa
Elisa il 19 Set 2014
I found another problem, that I corrected: It is not f = @(x, unused) asin(1./x); but f = @(x, unused) asin(x); (I made an error in the geometrical computation), but now I received another declaration by Matlab: ??? Error using ==> imtransform>check_udata at 606 'UData' elements cannot be equal unless A has only one column.
Error in ==> imtransform>parse_inputs at 386 args.udata = check_udata(varargin{k+1}, args.A);
Error in ==> imtransform at 264 args = parse_inputs(varargin{:});

Community Treasure Hunt

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

Start Hunting!

Translated by