Skip to content

Commit

Permalink
Fix LUV normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Jun 8, 2024
1 parent b0d4144 commit 7dabe69
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ workspace = { members = ["./src/app"] }

[package]
name = "histogram_equalization"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
description = "Histogram equalization"
readme = "README.md"
Expand Down
4 changes: 2 additions & 2 deletions src/app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use colorutils_rs::rgb_to_rgba;
use image::GenericImageView;
use image::io::Reader as ImageReader;

use histogram_equalization::{clahe_hsl_rgba, clahe_lab_rgb, clahe_lab_rgba, ClaheGridSize, hist_equal_luv_rgb};
use histogram_equalization::{clahe_hsl_rgba, clahe_lab_rgb, clahe_lab_rgba, clahe_luv_rgba, ClaheGridSize, hist_equal_luv_rgb};

fn main() {
let img = ImageReader::open("assets/asset_2.jpg")
Expand All @@ -29,7 +29,7 @@ fn main() {
let stride = dimensions.0 as usize * channels;
let mut dst_bytes: Vec<u8> = vec![0; stride * dimensions.1 as usize];

clahe_lab_rgba(
clahe_luv_rgba(
src_bytes,
stride as u32,
&mut dst_bytes,
Expand Down
14 changes: 7 additions & 7 deletions src/luv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ pub(crate) fn generic_image_to_luv<const IMAGE: u8>(
let luv = rgb.to_luv();
unsafe {
*new_slice.get_unchecked_mut(h_px) = (luv.l * full_scale).round().min(scale) as u16;
*new_slice.get_unchecked_mut(h_px + 1) = luv.u as u16;
*new_slice.get_unchecked_mut(h_px + 2) = luv.v as u16;
// Just for storing in u16 adding 500 to subtract 500 after to keep values in positive range
*new_slice.get_unchecked_mut(h_px + 1) = (luv.u + 500f32) as u16;
*new_slice.get_unchecked_mut(h_px + 2) = (luv.v + 500f32) as u16;
if image_configuration.has_alpha() {
let a = *src.get_unchecked(
src_offset + px + image_configuration.get_a_channel_offset(),
Expand Down Expand Up @@ -81,11 +82,10 @@ pub(crate) fn luv_to_generic_image<const IMAGE: u8>(

let l = unsafe { *source_slice.get_unchecked(px) } as f32 * full_scale;

let rgb = Luv::new(
l,
unsafe { *source_slice.get_unchecked(px + 1) } as f32,
unsafe { *source_slice.get_unchecked(px + 2) } as f32,
);
let u = unsafe { *source_slice.get_unchecked(px + 1) } as f32 - 500f32;
let v = unsafe { *source_slice.get_unchecked(px + 2) } as f32 - 500f32;

let rgb = Luv::new(l, u, v);
let rgb = rgb.to_rgb();
unsafe {
*dst.get_unchecked_mut(
Expand Down

0 comments on commit 7dabe69

Please sign in to comment.