Info

This question is closed. Reopen it to edit or answer.

How can i increase my contrast using pso and dwt?

1 view (last 30 days)
AARTI PAREYANI
AARTI PAREYANI on 13 Jul 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
clear all clc % m=imread('C:\Users\Welcome\Desktop\kuu.jpg') k=rgb2gray(m); figure(1) imhist(k) s=k-60; figure(2) imhist(s) swarm_size = 256; maxIter = 256; inertia = 1; correction_factor = 0.35; % set the position of the initial swarm swarm(1:swarm_size,1:256) = s; q=mat2gray(s); y=histeq(q); %% define the objective funcion here (vectorized form) %for j=1:10 for iter = 1:maxIter objfcn = @(x)(x(:,1) - 20).^2 + (x(:,1) - 25).^2; swarm(:,256) = swarm(:,256) + swarm(:,256)/1.19; %update x position with the velocity+ x = swarm(:,256); % get the updated positio fval = objfcn([x]); % evaluate the function using the position of the particle
% compare the function values to find the best ones
for ii = 1:swarm_size
if fval(ii,1) < swarm(ii,1)
swarm(ii,1) = swarm(ii,1); % update best x position,
swarm(ii,1) = fval(ii,1); % update the best value so far
end
end
[~, gbest] = min(swarm(:,256)); % find the best function value in total
test2=im2double(swarm);
% update the velocity of the particles
test2(:,1) = inertia*(rand(swarm_size,1).*test2(:,2)) + correction_factor*(rand(swarm_size,1).*(test2(:,3) ...
- test2(:,1))) + correction_factor*(rand(swarm_size,1).*(test2(gbest,3) - test2(:,1)));
end
%end
o=mat2gray(test2);
% p=histeq(o);
[LL,HL,LH,HH] = dwt2(o,'db8');
LL1=LL+mean2(LL)+0.5*(mean2(LL));
temp1=idwt2(LL1,HL,LH,HH,'db8');
figure(3)
subplot(4,2,1), imshow(k)
subplot(4,2,2), imhist(k)
subplot(4,2,3), imshow(y)
subplot(4,2,4), imhist(y)
subplot(4,2,5), imshow(temp1)
subplot(4,2,6), imhist(temp1)
%Calculate MSE, mean square error.
mseImage = (uint8(s)-uint8(temp1)).^2;
mse = sum(mseImage) / (256 * 256);
avgmse=mean(mse)
% Calculate PSNR (Peak Signal to noise ratio)
psnr_Value = 10 * log10( 256^2 / avgmse)

Answers (0)

Community Treasure Hunt

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

Start Hunting!