Contrast image enhancement using neighboring

Hi, I want to improve the contrast of the image using the pixel values ​​of the neighborhood.

Let the image be considered u0. Then I want to improve the image using the formula

enter image description here

Here, M1 are the minima, and M2 are the u0 maxima among the pixels of the neighborhood, Mg is the maximum gray level of the original image. The area for my operation is 9X9. uN - new generated image (image with contrast gain).

I tried the following code, but not sure if I am right or not.

%Generate a contrast enhanced image tic clear all; close all; I = imread('4.jpg'); I = imresize(I,[128 128]); if size(I,3)== 3 P = rgb2gray(uint8(I)); P = double(P); elseif size(I,3) == 2 P = 0.5.*(double(I(:,:,1))+double(I(:,:,2))); else P = double(I); end ssize=9; mg=max(P(:)); f1 = @(x) min(x(:)); m1 = nlfilter(P,[9 9],f1); f2 = @(x) max(x(:)); m2 = nlfilter(P,[9 9],f2); P_op=((P-m1)./(m2-m1)).*mg; subplot(2,1,1),imagesc(P,[0 255]);colormap(gray);axis off; subplot(2,1,2),imagesc(P_op,[0 255]);colormap(gray);axis off; toc 

Listed below are some of the results that I got:

enter image description hereenter image description hereenter image description hereenter image description here

Can anyone check and tell if my code is correct or not? I am not so sure of myself. Also, please tell me if there is a better way to do this. Thanks in advance guys.

CONNECTED question I am re-reading the work, and I ** should apply the sliding window function to only a few specified pixels. **

This method has detected pixels that I must apply. An original image outline has been detected (displayed in red on images). Then, a strip around the contour is drawn at a given distance. The sliding window function should be applied only to those pixels in a narrow strip for the source images.

I give images as well as initial contours and strip images.

enter image description hereenter image description hereenter image description hereenter image description here

The pixels marked in white are my specified pixels on which the slip function should be performed . Can such criteria be applied? Please help. I will clarify if my question is incorrect.

+7
image-processing matlab contrast sliding-window
source share
1 answer

I would solve it in one of the following two ways:

  • Apply a filter over the entire image (using colfilt instead of nlfilter ).
    Then multiply the result by the mask.
  • Extract the required pixels and their surroundings, forming them in the form of a column, for example colfilt , and apply a filter.

In any case, this will work. I think the first one will be faster for small photos.

0
source share

All Articles