Question

So I need to improve segmentation on an image. This is done by a really easy and straight-forward algorithm which is the following -

Loop through the whole image (the green channel of img.jpg) For each pixel, P

  • Compute the average grey value of the 21 by 21 pixel region centred on P, call it A
  • Multiply the value of P by 128/A

I am unsure about how to write the code, since I am new to Matlab (started learning it today basically). Any suggestions on how to implement the algorithm correctly?

Était-ce utile?

La solution

Try this -

f = imread('img.jpg');
greenChannel = f(:,:,2);

h = fspecial('average', 21);  %%// Kernel to be used for averaging
%h = ones(21,21)/(21*21); %%// Same as above, but custom-made
A = imfilter(greenChannel,h); %%// Average values for each pixel

newgreenChannel = greenChannel.*(128./A);
figure,imshow(newgreenChannel)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top