필터 지우기
필터 지우기

Image Processing/Matrix Math Question

조회 수: 1 (최근 30일)
John Moseley
John Moseley 2013년 5월 17일
댓글: arron 2014년 1월 2일
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

채택된 답변

Image Analyst
Image Analyst 2013년 5월 18일
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);

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by