obtener un area de una imagen

37 Ansichten (letzte 30 Tage)
nicolas chauta
nicolas chauta am 24 Mai 2020
Kommentiert: Image Analyst am 28 Mai 2020
necesito dibujar un poligono desde una imagen "x" y que permita recortar dicho poligono a otra matriz o fig, con ello poder calcular el area, perimetro, y longitudes.
las funciones que he utilizado son: impoly, drawpolygon las cuales me permiten dibujar el poligono, pero no sé como pasarla a otra fig. el impcrop no me sirve puesto que es un rectangulo que recorta la imagen

Antworten (2)

Image Analyst
Image Analyst am 25 Mai 2020
Try imfreehand(), impoly(), drawpoints(), or roipolyold()
imshow('cameraman.tif');
uiwait(helpdlg('Draw a polygon with left clicks. Right click to finish it.'));
[mask, xv, yv] = roipolyold();
hold on;
plot(xv, yv, 'r-', 'LineWidth', 2);
props = regionprops(mask, 'Area', 'Perimeter');
area = props.Area
perimeters = props.Perimeter
lengths = pdist2([xv,yv], [xv, yv])
maxLength = max(lengths(:))
Also look at bwferet() to get lengths.

Alejandro Peñuelas
Alejandro Peñuelas am 25 Mai 2020
Bearbeitet: Alejandro Peñuelas am 25 Mai 2020
¿Lo que necesitas es recortar un área de una imagen inicial y poner esa misma área en otra imagen?
Si es eso lo que necesitas, puedes probar lo siguiente:
/ You need to crop an image area to paste into another image? You can try this:
% Load the images / Cargar las imágenes
im1 = imread('image1.png');
im2 = imread('image2.png');
Image 1:
Image 2
Image 2:
Image 2
Supongamos queremos tomar una región poligonal desde la imagen 1 y luego ponerla en la 2. Para ello podemos hacer la selección del área a mano o con coordenadas. En este caso, dibujaré la región a mano para el ejemplo.
/ Let suppose that we want to select a region from image 1 and next paste it into image 2. So, we can select the area by hand or with coordinates. In this case, I draw the region by hand for this example.
% Show the image and create a ROI / Mostramos la imagen y creamos la ROI
imshow(im1);
roi = images.roi.Polygon; % Creata the ROI object with Polygon / Creamos un objeto ROI polígono
roi.draw; % With 'draw' method we start to draw the ROI by hand / Utilizamos el método 'draw' para iniciar la herramienta de dibujado a mano alzada
Con esto, podremos dibujar la región de interés con un polígono en la figura que muestra la imagen 1. Dando click sobre la imagen se dibujan los vértices del polígono. Cerramos la figura dando doble click (esto produce el vértice final). El resultado debe ser parecido al siguiente:
/ By doing this, we can draw the region of interest with a polygon into the matlab figure thath shows the image 1. By clicking on the image we create the polygon vertices. We can close the polygon with double click (this produces the final vertex). The result must be similar to the next image.
Para llevar la información de la imagen 1 a la 2 necesitamos crear una máscara binaria que nos indique qué elementos de la imagen queremos seleccionar para procesarlos. Entonces usamos la información en la ROI para hacer la márcara y luego la mostramos.
/ To use information from image 1 and paste it into the image 2, we can create a binary mask that indicates which elements will be selected for processing.Theh, we use ROI information to create the mask and nexw we show the mask.
% Create the binary mask from a ROI / Crear una máscara binaria a partir de una ROI
binMask = createMask(roi); % It produces a binary mask of the ROI / Produce una máscara binara a partir de la ROI
figure;
imshow(binMask);
Así, ya tenemos lo necesario para tomar la información de la imagen 1 y ponerla en la 2.
/ Now, we have the necessary to crop information from image 1 ans paste it into image 2.
% Copy the im2 / Copiar la imagen 2 en la nueva imagen
imCrop = im2;
% According to the binary mask, replace the elments of 'imCrop' with the elements of 'im1' / De acuerdo a la máscara binaria, reemplazamos los elementos en imCrop con los de im1
imCrop(binMask) = im1(binMask);
figure;
imshow(imCrop);
Espero que te sea de ayuda. Saludos.
/ I hope this can help you.
  5 Kommentare
nicolas chauta
nicolas chauta am 28 Mai 2020
muchas gracias, ya di solucion al problema
Image Analyst
Image Analyst am 28 Mai 2020
For what it's worth, I'm attaching a freehand drawing copy and paste demo, and also one for rectangles.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Display Image finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by