Image Processing/Matrix Math Question
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I have an m-by-n matrix of numerical values which correspond to weighting factors (essentially intensities) applied to each point (x,y) in an x-y coordinate system. What I would like to do is apply a function f(x,y) to each point (x,y) and then multiply the function by the weighting factor. This would hopefully result in another m-by-n matrix. In addition, I would like to sum up the values of the resulting matrix.
I would appreciate any help on this problem.
Thank you much,
John
0 commentaires
Réponse acceptée
Image Analyst
le 18 Mai 2013
That is exactly what the nlfilter() functions does. Here's your demo:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
A = imread('cameraman.tif');
[rows columns] = size(A);
A = im2double(A);
fun = @(x) median(x(:));
B = nlfilter(A,[5 5],fun);
subplot(2,2,1);
imshow(A)
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Display image B
subplot(2,2,2);
imshow(B)
title('Function applied to image', 'FontSize', fontSize);
% Get array of weights the same size as the image.
weights = peaks(256);
weights = weights - min(weights(:)); % Make all positive.
subplot(2,2,3);
imshow(weights, [])
title('Our weights', 'FontSize', fontSize);
% Multiply weights by image.
outputImage = weights .* B;
% Display image outputImage
subplot(2,2,4);
imshow(outputImage, [])
title('Now with weights applied', 'FontSize', fontSize);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Image Preview and Device Configuration dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!