how to extract an image and resize it?
1 次查看(过去 30 天)
显示 更早的评论
回答(1 个)
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
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!