How to create the same png icon but with a different color?

2 ビュー (過去 30 日間)
Akbar
Akbar 2019 年 3 月 7 日
コメント済み: Image Analyst 2019 年 3 月 9 日
Here is a .png of a button icon.
I need exactly the same icon, with the same style but a green color.
How can I achieve that?

採用された回答

Image Analyst
Image Analyst 2019 年 3 月 8 日
Try this:
redButton = imread('red button.png');
[rows, columns, numberOfColorChannels] = size(redButton)
% Convert to Hue, saturation, value color space.
hsvImage = rgb2hsv(redButton);
% Make hue 0.3. Adjust as needed.
hsvImage(:, :, 1) = 0.3 * ones(rows, columns);
% Go back to RGB space
greenButton = im2uint8(hsv2rgb(hsvImage));
% Display both images.
subplot(2, 1, 1);
imshow(redButton);
subplot(2, 1, 2);
imshow(greenButton);
0000 Screenshot.png
If you want to cycle through a bunch of colors to see them all, try this:
for h = 0 : 0.05 : 1
redButton = imread('red button.png');
[rows, columns, numberOfColorChannels] = size(redButton)
hsvImage = rgb2hsv(redButton);
% Make hue the current h color.
hsvImage(:, :, 1) = h * ones(rows, columns);
greenButton = im2uint8(hsv2rgb(hsvImage));
% Display both images.
subplot(2, 1, 1);
imshow(redButton);
subplot(2, 1, 2);
imshow(greenButton);
drawnow
promptMessage = sprintf('This Hue = %.2f\nDo you want to Continue, or Quit?', h);
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if contains(buttonText, 'Quit')
break;
end
end
  2 件のコメント
Akbar
Akbar 2019 年 3 月 9 日
Thank you very much, very interesting, I can even have other colors!
How about corners? They appear black. How to make them white or maybe transparent?
Image Analyst
Image Analyst 2019 年 3 月 9 日
Not sure. Just try a search: Search for PNG transparent

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 3 月 7 日
img = imread('ButtonRed.png');
mask = img(:,:,2) < 128; %true for red areas but false for white areas
npix = nnz(mask);
temp = [zeros(npix,1), ones(npix,1), zeros(npix,1)]; %green
img(repmat(mask,1,1,3)) = temp;
imwrite(img, 'ButtonGreen.png');

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品


リリース

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by