Determine a regions average in MATLAB

后端 未结 2 749
面向向阳花
面向向阳花 2021-01-24 16:21

I need some help with RGB capture in a image. I am using impixel to manualy get RGB from a picture, but i would like to create a grid of let\'s say 20x20 px boxes where it will

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-24 17:24

    Depending on your exact needs I see two solutions:

    Downscale the image using impyramid(img, 'reduce'). This gives you a smaller image consisting of average values of the original image. Then do what you did before to access single pixels. Repeat as often as necessary to get 2x2, 4x4, 8x8 or larger "boxes".

    Or you could use define a box (or arbitrary shape) as a matrix of ones and zeros and use the regionprops function in order to get information about the images content depending on the fields containing ones:

    roi = zeros(size(img))
    roi(1:10,1:10) = 1;
    r = regionprops(roi, img, 'MeanIntensity')
    average = r.MeanIntensity
    

提交回复
热议问题