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?

Was it helpful?

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top