Matlab – simple half-toning example

· DIP, Matlab
Authors

Hi 🙂

Let’s Map each pixel from the source image (grayscale) to 4 pixels in the destination image (binary), such that each destination pixel is “lighted” with white (1), based on a different thresholding:

[0-50] – do nothing

[51-101] – light #3

[102-152] – light #2

[153-203] – light #4

[204-255] – light #1

 

Function code:

function [ imgOut ] = half_toning( imgIn )
imgOut = zeros(size(imgIn)*2);

for i = 1 : size(imgIn, 1)
  for j = 1: size(imgIn, 2)
    if imgIn(i, j) > 50
      imgOut(i*2, j*2 + 1) = 1;
    end
    if imgIn(i, j) > 101
      imgOut(i*2 + 1, j*2) = 1;
    end
    if imgIn(i, j) > 152
      imgOut(i*2 + 1, j*2 + 1) = 1;
    end
    if imgIn(i, j) > 203
      imgOut(i*2, j*2) = 1;
    end
  end
end
end

 

Main program code:

clear all;
close all;

imgIn=imread(‘../images/kidface.jpg’);
figure(‘Position’, [0 0 10 10]);
title(‘source’);
imshow(imgIn);
figure;

figure(‘Position’, [0 400 10 10]);
title(‘half toned’);
imgOut = half_toning(imgIn);
imshow(imgOut);
figure;

 

Results:

Image

Image

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: