The following code converts an image histogram into finitely sparse histogram by using multiple thresholds that appear in histogram as peaks.
Input image in tif format:
code begins here:
clear all
#### Automatic way to make histogram of an image
#### highly sparse with thresholds observed in Histogram
#### Author: Rowthu Vijayakrishna
#### Date: 02-August-2014
#### Place:Dept. of Mathematics,IIT Kanpur
A=imread('Documents/octave/testIMGS/greyshade.tif');
for jump=1:3 ###jump is the maximum seperation in threshold values
do
B=A;
H=imhist(A,256);
plot(H);pause;
for i=1:size(A,1)
for j=1:size(A,2)
if H(1+A(i,j))<H(1+uint8(jump+A(i,j)))
A(i,j)=uint8(A(i,j)+jump);1
else if H(1+uint8(A(i,j)-jump))>H(1+A(i,j))
A(i,j)=uint8(A(i,j)-jump);2
endif;
endif;
endfor;
endfor;
until max(abs(B-A)(:))==0
endfor;
imwrite(A,'temp.tif');
printf('End of the programme\n');
Input image in tif format:
code begins here:
clear all
#### Automatic way to make histogram of an image
#### highly sparse with thresholds observed in Histogram
#### Author: Rowthu Vijayakrishna
#### Date: 02-August-2014
#### Place:Dept. of Mathematics,IIT Kanpur
A=imread('Documents/octave/testIMGS/greyshade.tif');
for jump=1:3 ###jump is the maximum seperation in threshold values
do
B=A;
H=imhist(A,256);
plot(H);pause;
for i=1:size(A,1)
for j=1:size(A,2)
if H(1+A(i,j))<H(1+uint8(jump+A(i,j)))
A(i,j)=uint8(A(i,j)+jump);1
else if H(1+uint8(A(i,j)-jump))>H(1+A(i,j))
A(i,j)=uint8(A(i,j)-jump);2
endif;
endif;
endfor;
endfor;
until max(abs(B-A)(:))==0
endfor;
imwrite(A,'temp.tif');
printf('End of the programme\n');
1 కామెంట్:
Version3:
Code starts from here.
clear all
#### Automatic way to make histogram of an image
#### highly sparse with thresholds observed in Histogram
#### Author: Rowthu Vijayakrishna
#### Date: 02-August-2014
#### Place:Dept. of Mathematics,IIT Kanpur
### version: 003
A=imread('greyshade.tif');
for check=1:2
for jump=1:11 ###jump is the maximum seperation in threshold values
do
B=A;
H=imhist(A,256);
#plot(H);
imhist(A,256);pause(1);
for i=1:size(A,1)
for j=1:size(A,2)
if H(1+A(i,j))H(1+A(i,j))
A(i,j)=uint8(A(i,j)-jump);2
endif;
endif;
endfor;
endfor;
until max(abs(B-A)(:))==0 ##### end of do-until loop
if (check==1)
imwrite(A,sprintf('temp%02d.tif',jump));
endif;
endfor; ### loop for jump thresholder
endfor; ### loop for second check
#imwrite(A,'temp.tif');
printf('End of the programme\n');
కామెంట్ను పోస్ట్ చేయండి