Crop an image without using "imcrop" function

10 ビュー (過去 30 日間)
Daniel Carvalho
Daniel Carvalho 2016 年 3 月 17 日
コメント済み: Daniel Carvalho 2016 年 3 月 17 日
Hi, I'm having a problem with this code (x and y are arrays):
function img2 = fcn(x,y,img1)
y1max = y(1,1) + y(1,17); x1max = x(1,1) + x(1,17);
img1=u(y(1,1):y1max,x(1,1):x1max);
end
Simulink gives me an error related with the type and size of variables. In my case, the arrays are in "int32" type. if i write the code with fixed values, the error fades away, for example:
function img2 = fcn(x,y,img1)
img1=u(100:150,50:200);
end
Can you help me? Regards, Daniel

回答 (1 件)

Image Analyst
Image Analyst 2016 年 3 月 17 日
編集済み: Image Analyst 2016 年 3 月 17 日
You forgot to give the actual error message - all the red text, not just a paraphrased snippet from it.
Actually I don't see how that code can work because you start to use a variable called "u" but that variable has apparently not been created in the function, nor been passed in through the argument list, so how could it possibly do anything with "u"?
I imagine the real error says something about U not existing, or else something about x and y being only 1-D vectors, not 2-D matrices.
  1 件のコメント
Daniel Carvalho
Daniel Carvalho 2016 年 3 月 17 日
Sorry, my mistake.
function img2 = fcn(x,y,img1)
y1max = y(1,1) + y(1,17); x1max = x(1,1) + x(1,17);
img2=img1(y(1,1):y1max,x(1,1):x1max);
end
Simulink gives me an error related with the type and size of variables. In my case, the arrays are in "int32" type. if i write the code with fixed values, the error fades away, for example:
function img2 = fcn(x,y,img1)
img2=img1(100:150,50:200);
end
Can you help me? Regards, Daniel

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by