how to subtract mask from an image and add the pixels value
8 次查看(过去 30 天)
显示 更早的评论
please help me to code for it. I did this code but not working properly.
clear all
close all
f = [12 30 120 220 120 130 140 150 120 220 120 120 90 80 70 80]
% f=imread('abc.jpg');
% f = rgb2gray(f);
m = f(2:3)
% m = imread('abc1.jpg');
% m = rgb2gray(m);
[R,C] = size(f);
for X = 1:R-(size(m,1))+1
for Y = 1:C-(size(m,2))+1
f1(X:X+size(m,1)-1,Y:Y+size(m,2)-1) = abs(f(X:X+size(m,1)-1,Y:Y+size(m,2)-1)-m);
end
end
subplot(1,3,1);
imshow(uint8(f));
subplot(1,3,2);
imshow(uint8(m));
subplot(1,3,3);
imshow(uint8(f1))
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226907/image.jpeg)
2 个评论
Guillaume
2019-6-30
Please use the toolbar buttons to format your post properly. I've done it this time but since the code was written on just one line, I had to take a guess at where the comments ended. I may have got it wrong.
Your explanation is really not clear. How is the mask calculated? What does subtracting the mask (a 1x2 vector) from a 1x8 image (a 1x8 vector) mean, bearing in mind that subtraction between two non-scalar vectors of different length is not defined? What does placing a result on mean? Do you mean assign to?
Image Analyst
2019-6-30
I agree with Guillaume. Your description is not clear and ambiguous - it could be interpreted several ways and your diagram is not helpful in explaining what values are in the mask, what is being subtracted, and what happens if parts of the mask are off the edge of the image. And if it's a 1x2 mask instead of a odd length like is usually used, where the output pixel gets assigned to.
采纳的回答
KALYAN ACHARJYA
2019-6-30
f=[12 30 120 220 120 130 140 150 120 220 120 120 90 80 70 80]
[r c]=size(f);
m=f(2:3)
f1=[];
for i=1:r
for j=1:c
sub_result=f(i,j)-m
f1(i,j)=sum(sub_result(:))
end
end
subplot(1,3,1);imshow(uint8(f));subplot(1,3,2);imshow(uint8(m));
subplot(1,3,3);imshow(uint8(f1));
3 个评论
KALYAN ACHARJYA
2019-6-30
编辑:KALYAN ACHARJYA
2019-6-30
See its doing, see in imshow, the f image and f1 is different
>> f
f =
12 30 120 220 120 130 140 150 120 220 120 120 90 80 70 80
>> f1
f1 =
-126 -90 90 290 90 110 130 150 90 290 90 90 30 10 -10 10
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!