How to multiply mask matrix and original image matrix?

5 views (last 30 days)
I am doing my final year project in my college. I have done a piece of my project work. But I didn't get the expected result.I have included my project base paper.Please help me to complete my project soon and thanks for your time. My code is here below.
clc;
clear all;
close all;
rgb=imread('img3.jpg');
RGB=rgb;
figure;
imshow(rgb);
title('Original Image');
%rect=imrect;
%ellipse=imellipse;
%poly=impoly;
%figure('Removed');
%Blue=RGB(:,:,3);
RGB(:,:,3)=0;
%Green=RGB(:,:,2);
RGB(:,:,2)=0;
% For Region of Interest selection and fill the region with white and outside with black
Ims=roipoly(RGB);
figure;
imshow(Ims);
title('ROI Image');
[row, column, dimen]=size(Ims);
%for d=3:-1:1
% for i=1:1:row
% for j=1:1:column
% if(d==1)
% RGB(:,:,1)=Ims(i,j);
% elseif(d==2)
% RGB(:,:,2)=Green(i,j);
% else
% RGB(:,:,3)=Blue(i,j);
% end;
% end;
% end;
%end;
% RGB(:,:,3)=Blue;
% RGB(:,:,2)=Green;
RGB(:,:,1)=Ims;
figure;
imshow(RGB);
title('Mask Image');
%image optimisation
%optimised=double(rgb).*double(RGB);
optimised = bsxfun(@times,rgb,RGB);
figure;
imshow(optimised);
title('Optimised Image');

Answers (1)

DGM
DGM on 6 May 2023
The problem with not getting the expected results is that unless it's clear what you're expecting, nobody will know. I'm going to assume that most of the given code can just be deleted.
% read the image
inpict = imread('peppers.png');
% interactively create selection
%mask = roipoly(inpict);
% since interactive tools don't work in the forum editor,
% do it programmatically for purposes of demonstration
mask = poly2mask([100 100 400],[100 300 200],384,512);
% compose output image
outpict = bsxfun(@times,im2double(inpict),mask);
outpict = im2uint8(outpict); % assert output class
figure;
imshow(inpict);
title('Original Image');
figure;
imshow(mask);
title('Mask Image');
figure;
imshow(outpict);
title('Masked Image');

Community Treasure Hunt

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

Start Hunting!