4 x 4 Mask to Identify Regions on Map with Highest Value

2 visualizzazioni (ultimi 30 giorni)
Good afternoon everyone!
I have a 360 x 576 matrix that represents a map of the world (latitude and longitude, respectively). Each of the elements in the matrix has a value between 0 and 100 that represents the amount of precipitation present at that geographic location. I would like to create a mask that checks every 4 rows by 4 columns to identify those regions on the "map" with the highest concentration of values. Essentially, I am looking for those regions where intense precipitation concentrates so that I may further inspect these geographic locations. Here, I think finding the average of the 4 x 4 mask might be helpful, but I don't know how to apply the averaging method to the entire matrix without overlapping. Also, I'm unsure if I can "highlight" the top five or so "4 x 4 boxes" with the highest values for the entire matrix. Any suggestions? I'm actively working on the problem but would appreciate any ideas. Thanks!
Michelle

Risposta accettata

Image Analyst
Image Analyst il 19 Lug 2020
Try this:
% Demo to find 4x4 regions with the highest sum value.
clc; % Clear the command window.
fprintf('Beginning to run %s.m ...\n', mfilename);
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing
fontSize = 15;
% Get temperature array with temps between 20 and 30 degrees celsius.
grayImage = 20 + 10 * rand(360, 576);
subplot(2, 1, 1);
imshow(grayImage, [])
impixelinfo; % Let user see RGB values as they mouse around.
colorbar
axis('on', 'image');
title('Original Image', 'FontSize', fontSize);
% Maximize the window to make it easier to draw.
g = gcf;
g.WindowState = 'maximized'
fprintf('Done running %s.m ...\n', mfilename);
% Get kernel
kernel = ones(4, 4);
sumImage = conv2(grayImage, kernel, 'same');
subplot(2, 1, 2);
imshow(sumImage, []);
axis('on', 'image');
title('Sum Image', 'FontSize', fontSize);
% Find 5 highest sums
sortedValues = sort(sumImage(:), 'descend');
[highRows, highColumns] = find(sumImage >= sortedValues(5))
% Place red squares around those areas.
hold on;
MarkerSize = 30;
plot(highColumns, highRows, 'rs', 'MarkerSize', MarkerSize, 'LineWidth', 3);

Più risposte (1)

jonas
jonas il 19 Lug 2020
Using imresize from the image processing TB
%non-overlapping (use conv2 method 'valid' for overlapping)
A = imresize(Z,0.5,'box');
%get indices for max id
[val, id] = max(A,[],[1,2],'linear');
[x,y] = ind2sub(size(A),id)*2;
The indices are multiplied by a factor 2 to get indices in the original matrix.

Community Treasure Hunt

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

Start Hunting!

Translated by