i have coding for enhancement of contrast for image. NEED EXPLANATION FOR CODES BEING USED

[ m, n ] = size ( gray );
gray3d = zeros ( 8, m, n ) ;
%
% For pixel (I,J), GRAY3D(*,I,J) contains the 8 neighboring values.
%
gray = double ( gray );
gray3d(1,:,:) = circshift ( gray, [ -1, -1 ] );
gray3d(2,:,:) = circshift ( gray, [ -1, 0 ] );
gray3d(3,:,:) = circshift ( gray, [ -1, 1 ] );
gray3d(4,:,:) = circshift ( gray, [ 0, -1 ] );
gray3d(5,:,:) = circshift ( gray, [ 0, 1 ] );
gray3d(6,:,:) = circshift ( gray, [ 1, -1 ] );
gray3d(7,:,:) = circshift ( gray, [ 1, 0 ] );
gray3d(8,:,:) = circshift ( gray, [ 1, 1 ] );
%
% Average the values.
%
gray_average = sum ( gray3d ) / 8.0;
%
% The SUM operation on an (L,M,N) array returns a (1,M,N) array.
%
%
gray_average_2d(1:m,1:n) = gray_average(1,1:m,1:n);
%
% Compute the new value for the center pixel.
%
gray_contrast = ( 1.0 - s ) * gray_average_2d(:,:) + s * gray;
gray_contrast = uint8 ( gray_contrast );
%
% The pixels on the boundary have been handled incorrectly.
% A more careful treatment could correctly enhance their contrast too.
% Instead, just restore them to their original values.
%
gray_contrast(1,:) = gray(1,:);
gray_contrast(m,:) = gray(m,:);
gray_contrast(:,1) = gray(:,1);
gray_contrast(:,n) = gray(:,n);
return
end

Answers (1)

What are you doing? It sort of looks like a convolution but in some kind of crazy algorithm. What's the intent of this function? What are you doing that can't be done with conv2(), imfilter(), or imsharpen()? And, what is your question - you forgot to state it.

4 Comments

SIR I AM ENHANCING A GRAY SCALE IMAGE WITH THE CODING STATED..MAKING A FUNCTION AND INCREASING THE CONTRAST OF THE IMAGE. PLEASE HELP ME WITH UNDERSTANDING THE CODES LIKE GRAY(1,:,:) IS BEING USED FOR WHAT??
That's getting a X-Z plane of a 3D image at the location Y = 1. Y is the row and it's the first index. I'm more interested in what you want to do than in this code because this code is complicated and there may be better approaches, like the ones I already suggested. I know what it's doing but it's a very weird and inefficient way of doing it and it's just not worth the time to explain it to you when I can say it could be done a heck of a lot more simply with just two lines of code: one to make up the kernel and one to call imfilter.
ohk sir...actually what i want to do is enhance the contrast of the ultrasound image. by forming a mask and then working on pixel by pixel..then changing the value of the center pixel to the new sharpness formula that has been mentioned here. and then after putting that formula for all pixel values in that image, the contrast gets improves and hence obtaining the new ehanced image...please help me out with this if possible please
SIR ALSO IF YOU COULD PLEASE EXPLAIN ME WHAT THESE TWO LINES IN THE CODING MEAN.... The SUM operation on an (L,M,N) array returns a (1,M,N) array. gray_average_2d(1:m,1:n) = gray_average(1,1:m,1:n);
THANKS A LOT FOR YOUR HELP..

Sign in to comment.

Asked:

on 2 Mar 2014

Commented:

on 3 Mar 2014

Community Treasure Hunt

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

Start Hunting!