Bitmap/Histogram: Difference between revisions

m
m (→‎{{header|Phix}}: minor tidy)
Line 1,033:
 
=={{header|Phix}}==
Requires read_ppm() from [[Bitmap/Read_a_PPM_file#Phix|Read_a_PPM_file]], write_ppm() from [[Bitmap/Write_a_PPM_file#Phix|Write_a_PPM_file]]. <br>
Uses demo\rosetta\lena.ppm, whichincluded youin willthe havedistribution, toresults find/downloadmay tobe verified with demo/\rosetta yourself\viewppm.exw
Included<lang asPhix>-- demo\rosetta\Bitmap_Histogram.exw, results may(runnable be verified with demo\rosetta\viewppm.exwversion)
include ppm.e -- black, white, read_ppm(), write_ppm() (covers above requirements)
<lang Phix>function to_bw(sequence image)
 
sequence color
<lang Phix>function to_bw(sequence image)
integer lum
sequence hist = repeat(0,256)
for ix=1 to length(image) do
integer l = 1, r = 256
for jy=1 to length(image[ix]) do
integer ltot, rtot
integer pixel = image[x][y] -- red,green,blue
for i=1 to length(image) do
sequence r_g_b = sq_and_bits(pixel,{#FF0000,#FF00,#FF})
for j=1 to length(image[i]) do
colorinteger {r,g,b} = sq_divsq_floor_div(sq_and_bits(image[i][j]r_g_b, {#FF0000010000,#FF000100,#FF01}),
lum = floor(0.2126*r + 0.7152*g + {#010000,#0100,#01}0.0722*b)
lum = floor(0.2126*colorimage[1x] + 0.7152*color[2y] += 0.0722*color[3])lum
image[i][j] = lum
hist[lum+1] += 1
end for
end for
ltotinteger lo = 1, hi = hist[l]256,
rtot ltot = hist[rlo],
while l! rtot =r dohist[hi]
while lo!=hi do
if ltot<rtot then
llo += 1
ltot += hist[llo]
else
rhi -= 1
rtot += hist[rhi]
end if
end while
integer lum = llo
for i=1 to length(image) do
for j=1 to length(image[i]) do
Line 1,072:
 
sequence img = read_ppm("Lena.ppm")
img = to_bw(img)
write_ppm("LenaBW.ppm",img)</lang>
 
=={{header|PHP}}==
7,794

edits