Borrar filtros
Borrar filtros

how to subtract mask from an image and add the pixels value

3 visualizaciones (últimos 30 días)
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))
  2 comentarios
Guillaume
Guillaume el 30 de Jun. de 2019
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
Image Analyst el 30 de Jun. de 2019
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.

Iniciar sesión para comentar.

Respuesta aceptada

KALYAN ACHARJYA
KALYAN ACHARJYA el 30 de Jun. de 2019
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));
Recomended: You can look for Block processing to avoid loops
  3 comentarios
KALYAN ACHARJYA
KALYAN ACHARJYA el 30 de Jun. de 2019
Editada: KALYAN ACHARJYA el 30 de Jun. de 2019
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

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by