Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save maycuatroi1/68bd7d1ff5083155ac2e773aedfa7e08 to your computer and use it in GitHub Desktop.
Save maycuatroi1/68bd7d1ff5083155ac2e773aedfa7e08 to your computer and use it in GitHub Desktop.
function main()
output_image = 'output.png';
% Read image in grayscale
image = imread('9tjxfk.jpg');
if size(image, 3) == 3
image = rgb2gray(image);
end
% Create lookup table
table = uint8(0:255);
table(1:100) = 0;
table(101:200) = 100;
table(201:254) = 200;
table(255) = 255;
% Apply LUT transformation
transformed_image = lookup_table_transform(image, table);
% Save output image
imwrite(transformed_image, output_image);
% Concatenate and display
final_image = [image, transformed_image];
imshow(final_image);
end
function result = lookup_table_transform(image, table)
if numel(table) ~= 256
error("Lookup table must have exactly 256 values");
end
% Apply lookup table transformation
result = table(double(image) + 1); % MATLAB indices start at 1
end
%%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment