How do I find the local maxima near already specified points on an image?

1 ビュー (過去 30 日間)
Julie Abernathy
Julie Abernathy 2021 年 1 月 29 日
編集済み: Iuliu Ardelean 2021 年 1 月 29 日
I'm designing an image analysis application which analyzes an image to determine significant points, then plots the predetermined points onto a different image. I now want to find the local maximum pixel values near each of these points, or I would like to average some amount of pixels surrounding these points to get one value from each point. What is the best way to go about this?
Note: The pixel values near these points are not neccesarily maxima values in terms of the whole image, some of these values may even be near zero.

回答 (1 件)

Iuliu Ardelean
Iuliu Ardelean 2021 年 1 月 29 日
編集済み: Iuliu Ardelean 2021 年 1 月 29 日
Each image is a matrix. An RGB image is a 3d matrix of size (height, width, depth). The depth will be 3, i.e. red, green and blue.
If you know the coordinates of your points of interest, you can simply select those elements in the matrix around that point, like this:
m = imread('peppers.png');
% get a point of interest (poi)
x = 250;
y = 250;
sides = 30;
region_of_interest = m(x-sides:x+sides, y-sides:y+sides, :);
% average pixel colour as an RGB triplet
average_pixel_colour = mean(region_of_interest, [1 2])
% if you want the whitest pixel value, then this may be what you are looking for:
greyscale_region_of_interest = mean(region_of_interest, [3]); % you could use also rgb2gray instead
whitest_pixel_value = max(greyscale_region_of_interest, [], 'all')

Community Treasure Hunt

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

Start Hunting!

Translated by