Matlab在图像上创建窗口 [英] Matlab create window on image

查看:114
本文介绍了Matlab在图像上创建窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个16X16窗口,以在matlab中扫描整个图像,并在窗口中记录具有最大灰度的像素的位置和灰度值.

I need to create A 16X16 window to scan over an entire image in matlab and record the position and grey level value of pixel with largest grey level in window.

有人可以指导我如何执行此操作吗?无法找到在图像上创建窗口的任何帮助.

Can anyone guide me on how to do this? Cant find any help on creating windows on images.

谢谢

推荐答案

守旧派循环法-

%%// Outputs that you are interested in are - img, x1 and y1
img = rgb2gray(input_image); %%// Gray level values
x1 = zeros(size(img)); %%// Row values for the maximum pixel in the 16x16 window
y1 = zeros(size(img)); %%// Column values for the maximum pixel in the 16x16 window
for k1= 1:size(img,1)-15
    for k2= 1:size(img,2)-15
        img1 = img(k1:k1+15,k2:k2+15);        
        [val,ind1] = max(img1(:));
        img(k1+8,k2+8)=val; %%// Store the max grey value into the image
        [x1(k1,k2),y1(k1,k2)] = ind2sub([16 16],ind1);
    end
end

要在此滑动窗口中计算平均值,请使用此-

Edit 1: For calculating mean across this sliding window, use this -

window_size = 16; %%// Edit this to your window size

wsz = window_size-1;
mp = round(window_size/2);

%%// Outputs that you are interested in are - img, x1 and y1
img = rgb2gray(input_image); %%// Gray level values
x1 = zeros(size(img)); %%// Row values for the maximum pixel in the 16x16 window
y1 = zeros(size(img)); %%// Column values for the maximum pixel in the 16x16 window

img1 = img;
for k1= 1:size(img,1)-wsz
    for k2= 1:size(img,2)-wsz
        window_data = img(k1:k1+wsz,k2:k2+wsz);        
        val = round(mean(window_data(:)));
        img1(k1+mp,k2+mp)=val; %%// Store the mean grey value into the image
    end
end

figure,imshow(img1)

img1 = Z;
for k1= 1:size(Z,1)-wsz
    for k2= 1:size(Z,2)-wsz
        window_data = Z(k1:k1+wsz,k2:k2+wsz);        
        val = mean(window_data(:))
        if (val~=0)
            keyboard;
            error('Look, there is a non-zero mean value!');
        end
       % img1(k1+mp,k2+mp)=val; %%// Store the mean grey value into the image
        display(val);
    end
end

这篇关于Matlab在图像上创建窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆