# Imcrop and rectangle functions using "rect" but use different formats to specify

2 visualizaciones (últimos 30 días)
Jason el 22 de En. de 2024
Comentada: Jason el 22 de En. de 2024
Hello, Im using the value of rect below to determine th coordiantes of a rectangle of interest that I then use as an imput into the "rectangle" and "imcrop" functions. I see that the format of both "rects" is slightly different, with one having spaces and the other having commas.
I dont like defining the same thing twice, is it possible to derive the 2nd rect from the first rect?
rect=[margin+xcen+hw margin+ycen+hw 2*hw 2*hw]; %[x, y, width, height] (NO COMMA'S)
rectangle(ax,'Position',rect,'EdgeColor','y');
rect=[margin+xcen+hw, margin+ycen+hw, 2*hw, 2*hw]; %(WITH COMMA'S)
ImTL=imcrop(IM,rect);
Thanks
Jason
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Sai Teja G el 22 de En. de 2024
Editada: Sai Teja G el 22 de En. de 2024
Hi Jason,
Please see the following sample code, which demonstrates that you can declare the "rect" variable just once and still achieve the expected result. The spaces and commas in the vector are both valid MATLAB syntax for creating an array, and they are functionally equivalent.
% Sample values for the rectangle parameters
margin = 10;
xcen = 50;
ycen = 75;
hw = 20;
% Create a sample image (a 200x200 black image for this example)
IM = zeros(200, 200);
% Create a figure and axes
figure;
ax = axes;
rect=[margin+xcen+hw,margin+ycen+hw,2*hw,2*hw]; %[x, y, width, height]
rectangle(ax,'Position',rect,'EdgeColor','y');
ImTL = imcrop(IM, rect);
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Jason el 22 de En. de 2024
Great, thankyou

Iniciar sesión para comentar.

### Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

R2022b

### Community Treasure Hunt

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

Start Hunting!

Translated by