How the difference(difference of adjacent pixel values) histogram of an image can be plot ?I want to generate a difference image and histogram of thedifference image.I have write a code,but getting an error.Please help.

3 views (last 30 days)
clc;
clear all;
close all hidden;
[file,path]=uigetfile('*.bmp;*.jpg','Pick an Image File');
if isequal(file,0) isequal(path,0) warndlg('User Pressed Cancel'); else Host_im=imread(file);
[r c p] = size(Host_im);
if p==3
Host_im = rgb2gray(Host_im);
end
figure(1);
imshow(Host_im);
title('Input Image');
end
X = inputdlg('Enter Value from 0 to 5');
L = str2num(X{1});
P = 2^L;
H = Host_im;
figure(2);
imhist(Host_im);
title('Histogram of Input Image(Fused Image)');
xlabel('Pixel value');
ylabel('No of pixels');
%%%%%%%%Histogram Shifting
location1 = find(Host_im<P);
location2 = find(Host_im>(255-P));
H(location1)=H(location1)+P;
H(location2)=H(location2)-P;
figure(3);
imshow(H,[]);
title('Image of Histogram Shifted Image');
figure(4);
imhist(H);
title('Histogram of Histogram Shifted Image');
xlabel('Pixel value');
ylabel('No of pixels');
%%%%%%To find pixel difference
Host_im = double(Host_im);
Row = r;
Col = c;
k =1;
for i = 1:Row
im_val = Host_im(i,:);
if mod(i,2)==0 %%%%%%%%%%checkreminder
d(k:i*Col,:) = im_val(end:-1:1)';
else
d(k:i*Col,:) = im_val(1:1:end)';
end
k = i*Col + 1;
end
Diff(1) = d(1);
Diff(2:length(d)) = abs(d(1:length(d)-1) - d(2:length(d)));
x = d; len = length(Diff); Row = r; Col =c; k =1; for i = 1:Row if mod(i,2)==0 star_p = Col; mid_p = -1; end_p = 1; else star_p = 1; mid_p = 1; end_p = Col; end for j = star_p:mid_p:end_p nw(i,j) = Diff(k); k = k+1; end end location14 = find(nw<P); location15 = find(nw>(255-P));
nw(location14)=nw(location14)+P; nw(location15)=nw(location15)-P;
figure(35);
imshow(nw,[]);
title('Image of difference Histogram Shifted Image');
figure(45);
imhist(nw);
[counts x]=imhist(nw)
title('Histogram of difference Histogram Shifted Image');
xlabel('Pixel value');
ylabel('No of pixels');
  2 Comments
Geoff Hayes
Geoff Hayes on 9 Jun 2014
Rather than pasting your code (some of which is formatted and some of which isn't), it would be simpler to just attach the file to your question (or any subsequent comment that you make) - use the paperclip icon to do so.
As well, you did not include the error message….
ATHIRA
ATHIRA on 10 Jun 2014
I want to plot the difference histogram so that i could find out the peak point of histogram for embedding capacity calculation.It is expected to get a higher peak point when the value of L is increased.But what the error i am getting is that, the peak point value is same,for all values of L from 0 to 5.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 9 Jun 2014
To get the difference image, you can do that all in one line with a single call to conv2(). Do you want the average of the difference in all 8 directions, or just the different in one directions? Either way, just make up your kernel for the situation you want and call conv2(). Then call hist() or histc() to get its histogram.
  4 Comments
Image Analyst
Image Analyst on 10 Jun 2014
The peak for the histogram will most likely be at 0, meaning that there is no difference between a pixel and its neighbor. In most cases this is to be expected. Why do you call that an error?
ATHIRA
ATHIRA on 12 Jun 2014
yes i got the peak value as zero. But i have shifted the histogram by a value p=2^L. P is assumed as the number of the peak point for embedding message bit.It is supposed to have a get a higher value of Np,ie number of pixels associated with the peak point.But for every value of L got the same Np

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!