Tôi có một hình ảnh trong MATLAB:Làm thế nào tôi có thể tìm thấy cực đại cục bộ trong một hình ảnh trong MATLAB?
y = rgb2gray(imread('some_image_file.jpg'));
và tôi muốn làm một số xử lý trên đó:
pic = some_processing(y);
và tìm ra cực đại địa phương của đầu ra. Đó là, tất cả các điểm trong y
lớn hơn tất cả các nước láng giềng của họ.
Tôi dường như không thể tìm thấy chức năng MATLAB để làm điều đó một cách độc đáo. Điều tốt nhất tôi có thể đưa ra là:
[dim_y,dim_x]=size(pic);
enlarged_pic=[zeros(1,dim_x+2);
zeros(dim_y,1),pic,zeros(dim_y,1);
zeros(1,dim_x+2)];
% now build a 3D array
% each plane will be the enlarged picture
% moved up,down,left or right,
% to all the diagonals, or not at all
[en_dim_y,en_dim_x]=size(enlarged_pic);
three_d(:,:,1)=enlarged_pic;
three_d(:,:,2)=[enlarged_pic(2:end,:);zeros(1,en_dim_x)];
three_d(:,:,3)=[zeros(1,en_dim_x);enlarged_pic(1:end-1,:)];
three_d(:,:,4)=[zeros(en_dim_y,1),enlarged_pic(:,1:end-1)];
three_d(:,:,5)=[enlarged_pic(:,2:end),zeros(en_dim_y,1)];
three_d(:,:,6)=[pic,zeros(dim_y,2);zeros(2,en_dim_x)];
three_d(:,:,7)=[zeros(2,en_dim_x);pic,zeros(dim_y,2)];
three_d(:,:,8)=[zeros(dim_y,2),pic;zeros(2,en_dim_x)];
three_d(:,:,9)=[zeros(2,en_dim_x);zeros(dim_y,2),pic];
Và sau đó xem nếu tối đa dọc theo chiều thứ 3 xuất hiện trong lớp 1 (có nghĩa là: three_d(:,:,1)
):
(max_val, max_i) = max(three_d, 3);
result = find(max_i == 1);
Có thêm thanh lịch cách để làm điều này? Điều này có vẻ như một chút của một kludge.
câu hỏi liên quan: [Làm thế nào tôi có thể tìm thấy nhiều maxima địa phương trong một hình ảnh ồn ào?] (http://stackoverflow.com/questions/2706528/finding-many-local-max-in-an-image-using-matlab) –