Bitmap/Histogram: Difference between revisions
m
→{{header|Perl 6}}: bleh. e before h
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Add perl 6 example) |
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: bleh. e before h) |
||
Line 923:
ibw( img <= m ) = 0;
jpgwrite("lennamed.jpg", ibw, 100);</lang>
=={{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]]. ▼
Uses lena.ppm, which you will have to find/download to demo/rosetta yourself.▼
Included as demo\rosetta\Bitmap_Histogram.exw, results may be verified with demo\rosetta\viewppm.exw▼
<lang Phix>function to_bw(sequence image)▼
sequence color▼
integer lum▼
sequence hist = repeat(0,256) ▼
integer l = 1, r = 256▼
integer ltot, rtot▼
for i=1 to length(image) do▼
for j=1 to length(image[i]) do▼
color = sq_div(sq_and_bits(image[i][j], {#FF0000,#FF00,#FF}),▼
{#010000,#0100,#01})▼
lum = floor(0.2126*color[1] + 0.7152*color[2] + 0.0722*color[3])▼
image[i][j] = lum▼
hist[lum+1] += 1▼
end for ▼
end for ▼
ltot = hist[l]▼
rtot = hist[r]▼
while l!=r do▼
if ltot<rtot then▼
l += 1▼
ltot += hist[l]▼
else▼
r -= 1▼
rtot += hist[r]▼
end if▼
end while▼
lum = l▼
for i=1 to length(image) do▼
for j=1 to length(image[i]) do▼
image[i][j] = iff(image[i][j]<lum?black:white)▼
end for ▼
end for ▼
return image▼
end function▼
sequence img = read_ppm("Lena.ppm")▼
img = to_bw(img)▼
write_ppm("LenaBW.ppm",img)</lang>▼
=={{header|Perl 6}}==
Line 1,025 ⟶ 982:
See [https://github.com/thundergnat/rc/blob/master/img/Lenna.png Lenna], and [https://github.com/thundergnat/rc/blob/master/img/Lenna-bw.png Lenna-bw] images. (converted to .png as .ppm format is not widely supported).
▲=={{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]].
▲Uses lena.ppm, which you will have to find/download to demo/rosetta yourself.
▲Included as demo\rosetta\Bitmap_Histogram.exw, results may be verified with demo\rosetta\viewppm.exw
▲<lang Phix>function to_bw(sequence image)
▲sequence color
▲integer lum
▲sequence hist = repeat(0,256)
▲integer l = 1, r = 256
▲integer ltot, rtot
▲ for i=1 to length(image) do
▲ for j=1 to length(image[i]) do
▲ color = sq_div(sq_and_bits(image[i][j], {#FF0000,#FF00,#FF}),
▲ {#010000,#0100,#01})
▲ lum = floor(0.2126*color[1] + 0.7152*color[2] + 0.0722*color[3])
▲ image[i][j] = lum
▲ hist[lum+1] += 1
▲ end for
▲ end for
▲ ltot = hist[l]
▲ rtot = hist[r]
▲ while l!=r do
▲ if ltot<rtot then
▲ l += 1
▲ ltot += hist[l]
▲ else
▲ r -= 1
▲ rtot += hist[r]
▲ end if
▲ end while
▲ lum = l
▲ for i=1 to length(image) do
▲ for j=1 to length(image[i]) do
▲ image[i][j] = iff(image[i][j]<lum?black:white)
▲ end for
▲ end for
▲ return image
▲end function
▲sequence img = read_ppm("Lena.ppm")
▲ img = to_bw(img)
▲ write_ppm("LenaBW.ppm",img)</lang>
=={{header|PHP}}==
|