From: Kenneth Galea on
Hi everyone,

I have a black image (640x480) and want to select a area square/rectangle (of this image and make it white. Then I need to display the black image again with the white patch on it. I read about imcrop and imsubtract but still no clue. any help please??

Thanks
kenneth
From: Kenneth Galea on
"Kenneth Galea" <k.galea(a)hotmail.com> wrote in message <ho5h72$sav$1(a)fred.mathworks.com>...
> Hi everyone,
>
> I have a black image (640x480) and want to select a area square/rectangle (of this image and make it white. Then I need to display the black image again with the white patch on it. I read about imcrop and imsubtract but still no clue. any help please??
>
> Thanks
> kenneth
Sorry forgot to mention. The image is not always black but the patch on the image needs to be always white.
Thanks
Kenneth
From: ImageAnalyst on
Kenneth Galea
Use imcrop (I'm sure you'll figure it out) and then use poly2mask().

Or use imrect() and the createMask() method of imrect().
From: Kenneth Galea on
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <98732dee-2af0-4941-a72e-275045cc8b73(a)y17g2000yqd.googlegroups.com>...
> Kenneth Galea
> Use imcrop (I'm sure you'll figure it out) and then use poly2mask().
>
> Or use imrect() and the createMask() method of imrect().


Sorry to ask again. But I can't understand the purpose of imcrop if I use poly2mask() since from what I can see poly2mask(x,y,m,n) needs 4 input arguments where x and y are where pixels inside x and y are set to 1 while the rest are set to 0. here's my code :

white = imread('C:\Users\Kenneth\Desktop\white.jpg');
f = imread('C:\Users\Kenneth\Desktop\black.jpg');
size (f)
whos f
[m,n] = size (f);
X=m;
Y=n/3;

rect = [200 12 240 100] %selected area to crop
I2 = imcrop(f, rect) %crop specified black area
figure
imshow (I2) %show cropped area

x = [0 186 54 190];
y = [0 100 209 500];

BW = poly2mask(x, y, X, Y)
figure
imshow (BW)

I can't find a connection between rect and x,y & f and X, Y :/

Thanks
Kenneth
From: ImageAnalyst on
Kenneth Galea
imcrop just allows you to interactively set the bounding box. From
your code, it appears that you already know the coordinates of the
region to crop. In this case, you can simply use those coordinates
and not bother to ask the user where to crop. imcrop will give you
back a cropped grayscale image if you pass it a larger grayscale
image. poly2mask() will give you a binary image, unlike the grayscale
image that imcrop gives you. So if you want a binary mask, you need
to use poly2mask().

The 3rd and 4th arguments of poly2mask say what size you want the
output image to be. For example you might want a small box inside of
a much larger image. It appears that you are saying that you want the
mask image to be the same number of rows (X=m=#rows) as f (your badly-
named original image), and you want the number of columns (which
likewise you're deceptively calling Y) to be 1/3 the number of columns
as your original image. I have no idea why you're doing that. Your
"BW" is only 1/3 as wide as your original "f" image. Usually masks
are the same size as the image, but perhaps you have plans to apply
that mask to an as-of-yet-undefined image that's only 1/3 as wide as
your "f" image.

Finally, I have no idea where you're getting your x and y from - they
don't seem to be related to your cropping rectangle at all - you just
hard code them in. How did you come up with these? Why did you
crop? Is your mask supposed to have anything at all to do with your
cropping box?