Hey I want to change my gray image back to rgb.
This is my code
I1 = '3 new.jpeg';
img = imread(I1);
img_grey = rgb2gray(img);
A = img(:,:,3);
second_img = imsubtract(A, img_grey);
final_img = im2bw(second_img, 0.09);
imshow(final_img);
title('Final Img','fontsize',20);
rgbImage=ind2rgb(final_img,jet(256));
imshow (rgbImage);

댓글 수: 4

Image Analyst
Image Analyst 2021년 1월 13일
OK, congratulations. Actually you converted a binary image (not a gray scale image) into RGB. I don't see a question anywhere, but thanks for the announcement (I guess).
Raja Ahmad Shurim Raja Zainol
Raja Ahmad Shurim Raja Zainol 2021년 1월 14일
how to change it back to rgb actually?
rgbImage=ind2rgb(uint8(final_img), jet(256));
You will not be able to convert it back to the original color.
However it would be possible to use the binary image to select parts of the original image to stay the same and convert everything else to black.
finalrgb = img.*uint8(final_img) ;
Raja Ahmad Shurim Raja Zainol
Raja Ahmad Shurim Raja Zainol 2021년 1월 14일
when i using finalrgb = img.*uint8(final_img) ; in normal file it will show the final image but when i try to sub into gui, it cannot show the final image, why?

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2021년 1월 14일

0 개 추천

How did you call the display function, such as imshow(), in both cases? It should work the same. Are you using GUIDE or App Designer for the "GUI" method?
To change your gray scale image back into the original RGB image, you simply assign it:
img_grey = img;
That should work as long as you still have img available.

댓글 수: 3

i am using the GUIDE, below is my code, i try to make the when i load one image, it can detect the blue or colour in the picture and show the final image of the blue or red colour section, i still new at this image processing
% --- Executes on button press in loadimage.
function loadimage_Callback(hObject, eventdata, handles)
% hObject handle to loadimage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global I1
I1=imread(uigetfile('*.jpeg'));
subplot('Position', [0.2 0.2 0.6 0.6]);
imshow(I1);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global I1
img_grey = rgb2gray(I1);
A = I1(:,:,1); %1=red 2=green 3=blue
almostfinal_img = imsubtract(A, img_grey);
final_img1 = im2bw(almostfinal_img, 0.09);
img_grey=img;GUID
subplot('Position', [0.2 0.2 0.6 0.6]);
title('Position Red','fontsize',20);
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global I1
img_grey = rgb2gray(I1);
B = I1(:,:,3); %1=red 2=green 3=blue
almostfinal_img2 = imsubtract(B, img_grey);
final_img = im2bw(almostfinal_img2, 0.06);
subplot('Position', [0.2 0.2 0.6 0.6]);
imshow(final_img);
title('Position Blue','fontsize',20);
We recommend against using global.
subplot('Position', [0.2 0.2 0.6 0.6]);
subplot() of what axes in what figure?
Note: when you use subplot() and the position you give partly overlays an existing axes, the existing axes will be deleted.
img_grey=img;GUID
is GUID a function that you are intentionally calling there?
Note that in pushbuttoon2_Callback, you do not display anything.
Image Analyst
Image Analyst 2021년 1월 15일
Attach both the .m file and the .fig file with the paperclip icon if you need more help.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Convert Image Type에 대해 자세히 알아보기

제품

릴리스

R2020a

태그

댓글:

2021년 1월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by