how to extract an image and resize it?

2 visualizaciones (últimos 30 días)
Kritika
Kritika el 5 de Feb. de 2015
Comentada: Kritika el 5 de Feb. de 2015
I am enclosing an image. I want to extract only lena from it removing all the black boundaries and re-sizing it to 512x512 image.

Respuestas (1)

Image Analyst
Image Analyst el 5 de Feb. de 2015
Editada: Image Analyst el 5 de Feb. de 2015
Take the vertical and horizontal profiles and then use find() to find the bounding box
verticalProfile = mean(grayImage, 2);
horizontalProfile = mean(grayImage, 1);
topRow = find(verticalProfile, 1, 'first');
bottomRow = find(verticalProfile, 1, 'last');
leftColumn= find(horizontalProfile, 1, 'first');
rightColumn = find(horizontalProfile, 1, 'last');
croppedImage = grayImage(topRow:bottomRow, leftColumn:rightColumn);
[rows, columns, numberOfColorChannels] = size(croppedImage);
if rows ~= 512 || columns ~= 512
croppedImage = imresize(croppedImage, [512,512]);
end
  1 comentario
Kritika
Kritika el 5 de Feb. de 2015
this is not working. it just resized the image to 512x512.

Iniciar sesión para comentar.

Categorías

Más información sobre Images en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by