issue with rgb2ind

4 views (last 30 days)
Andrew Luce
Andrew Luce on 22 Sep 2022
Commented: Walter Roberson on 22 Sep 2022
Hello,
I just leared that back in the day that you could get a camera for your game boy. I was just interested into replicating the style of image that they made. I simply just used the stock pepper image, scaled the image to a multiple of 128x112 and tried to use rgb2ind to convert the image to "greyscale" or a "greenscale". I use indicies that I found but I keep getting a black image. What am I doing wrong?
for reference, this article shows how to create the effect with gimp
%% rescale image
Scale_Multiplier = 4;
rescale_size = [112,128].* Scale_Multiplier;
RGB2 = imresize(RGB,[rescale_size(1) rescale_size(2)]);
%% Greyscale or Greenscale
Gray_or_Green = 1;
%% Color image
if (Gray_or_Green ==0)
Color_Map = [0,0,0;128,128,128;192,192,192;255,255,255]; % Grey
Color_Map = Color_Map/255;
elseif (Gray_or_Green ==1)
Color_Map = [51,57,35;110,121,75;191,201,150;241,246,223]; % Green
Color_Map = Color_Map/255;
end
X = rgb2ind(RGB2,Color_Map);
imshow(X)

Answers (1)

Walter Roberson
Walter Roberson on 22 Sep 2022
RGB = imread('flamingos.jpg');
%% rescale image
Scale_Multiplier = 4;
rescale_size = [112,128].* Scale_Multiplier;
RGB2 = imresize(RGB,[rescale_size(1) rescale_size(2)]);
%% Greyscale or Greenscale
Gray_or_Green = 1;
%% Color image
if (Gray_or_Green ==0)
Color_Map = [0,0,0;128,128,128;192,192,192;255,255,255]; % Grey
Color_Map = Color_Map/255;
elseif (Gray_or_Green ==1)
Color_Map = [51,57,35;110,121,75;191,201,150;241,246,223]; % Green
Color_Map = Color_Map/255;
end
X = rgb2ind(RGB2,Color_Map);
RGBX = ind2rgb(X, Color_Map);
imshow(RGBX)
  2 Comments
Walter Roberson
Walter Roberson on 22 Sep 2022
Possibly dither instead of the rgb2ind() call ?

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!