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 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
ATHIRA
el 9 de Jun. de 2014
Comentada: ATHIRA
el 12 de Jun. de 2014
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 comentarios
Geoff Hayes
el 9 de Jun. de 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….
Respuesta aceptada
Image Analyst
el 9 de Jun. de 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 comentarios
Image Analyst
el 10 de Jun. de 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?
Más respuestas (0)
Ver también
Categorías
Más información sobre Histograms en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!