issue with rgb2ind

10 vues (au cours des 30 derniers jours)
Andrew Luce
Andrew Luce le 22 Sep 2022
Modifié(e) : DGM le 21 Mai 2023
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)

Réponses (2)

Walter Roberson
Walter Roberson le 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 commentaires
Andrew Luce
Andrew Luce le 22 Sep 2022
Thank you for the help. The only thing I'm wondering is if that it can change the dithering style to more like this?
Walter Roberson
Walter Roberson le 22 Sep 2022
Possibly dither instead of the rgb2ind() call ?

Connectez-vous pour commenter.


DGM
DGM le 21 Mai 2023
Modifié(e) : DGM le 21 Mai 2023
When I was adding gray2pcolor()/uniquant() to MIMT, I thought about this question. I took the time to add dithering modes to both to make this sort of thing possible. I decided to go the extra mile and just make a tool to do this one thing specifically.
MIMT now has gbcam().
inpictrgb = imread('hallway.jpg');
inpict = mono(inpictrgb,'y'); % convert to luma
% it usually helps to play with image brightness/contrast
inpict = imlnc(inpict,'g',1.2,'k',1.2);
scale = 2; % output scaling factor
% tan-tone like a GB pocket
A = gbcam(inpict,'newschool',scale);
% olive-tone like an original GB
B = gbcam(inpict,'oldschool',scale);
% slightly bright with muted extrema (gamma~0.8)
C = gbcam(inpict,'gray',scale);
% the common overly-bright gray map (gamma~0.68)
D = gbcam(inpict,'brigray',scale);
% a strictly linear gray map (gamma=1)
E = gbcam(inpict,'unigray',scale);
% concatenate for easier handling
outpict1 = [A B];
outpict2 = [C D E];
If you don't like these maps, you can specify your own as a 4x3 unit-scale color table.
% hmm i like that olive map, but i want the midtones brighter
CT = [0 59 61; 24 109 66; 47 160 72; 71 210 77]/255; % the given map
CT = ctshift(CT,0.3); % shift the map distribution
% use your new custom map
A = gbcam(inpict,CT,scale);
Images are automatically centered, scaled, and cropped to fit the output frame. If you want your image located differently, prepare it accordingly prior to feeding it to gbcam().
The functions gbcam(), mono(), imlnc(), and ctshift() are all from MIMT.

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by