Horizontal average on Image
Show older comments
Given that the mask is hor = 0 0 0, 1 1 1, 0 0 0
I have to apply to my image. Afterwards, find the sum and divide by 3.
My code is:
clear; % Clear the workspace
A = imread('Nature.jpg');
I = imrotate(A,90,'bilinear','loose');
grey = 0.21*I(:,:,1)+0.72*I(:,:,2)+0.07*I(:,:,3);
Grey = double(grey);
HorMask = [0 0 0;1 1 1;0 0 0];
[r,c] = size(Grey);
OUT = zeros(r-3,c-3);
for i = 1:(r-3)
for j = 1:(c-3)
GreySquare = Grey(i:(i+2),j:(j+2));
res = HorMask.*GreySquare;
Divide = res./3;
OUT(i,j) = sum(Divide);
end
end
figure()
imshow(OUT);
However, I am not able to divide by 3. with error message:
Subscripted assignment dimension mismatch.
Error in HorizontalAverage (line 16)
OUT(i,j) = sum(Divide);
1 Comment
Jan
on 6 Oct 2017
"I am not able" does not explain, what the problem is. Do you get an error message? If so, please post it completely. It is much easier to solve a problem than to guess, what the problem is.
Accepted Answer
More Answers (0)
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!