Filter löschen
Filter löschen

Image Processing/Matrix Math Question

1 Ansicht (letzte 30 Tage)
John Moseley
John Moseley am 17 Mai 2013
Kommentiert: arron am 2 Jan. 2014
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

Akzeptierte Antwort

Image Analyst
Image Analyst am 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);

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by