Info

This question is closed. Reopen it to edit or answer.

Why is my output B&W?

1 view (last 30 days)
Isabelle Berta
Isabelle Berta on 4 Jun 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
So im working on this project where I have to load the image1, select 10 points and save the cropped image to a folder. But im having problems with it because my output is showing B&W.. And also it only saves a black image with a white mark in it. How can I fix this? thanks
function save1_Callback(hObject, eventdata, handles)
a = imread('image1.jpg');
imshow(a);
[r c]=ginput(10);
bg = roipoly(a,r,c);
[R C] = size(bg);
for i=1:R
for j=1:C
if bg(i,j)==1
Out(i,j)=a(i,j);
else
Out(i,j)=0;
end
end
end
figure;
imshow(Out,[]);
imwrite(Out, 'C:\Users\Image Lab 2\Documents\MATLAB\ crop1.jpg');

Answers (1)

Image Analyst
Image Analyst on 4 Jun 2015
You're just getting 10 locations and Out is a monochrome image - it's not an RGB image, and you're just assigning it a value of either 0, or the value at linear index or your RGB image, which will be the wrong pixel. And I don't see any cropping going on. What do you want to do? Do you want to crop it or mask it to the polygon of 10 points? See my attached masking demos.

Community Treasure Hunt

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

Start Hunting!