필터 지우기
필터 지우기

how to extract an image and resize it?

조회 수: 2 (최근 30일)
Kritika
Kritika 2015년 2월 5일
댓글: Kritika 2015년 2월 5일
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.

답변 (1개)

Image Analyst
Image Analyst 2015년 2월 5일
편집: Image Analyst 2015년 2월 5일
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
Kritika
Kritika 2015년 2월 5일
this is not working. it just resized the image to 512x512.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by