Info

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

freehand_masking_demo.m on a .mat file

1 view (last 30 days)
komalben shah
komalben shah on 6 Nov 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
I have a grayscale image. I found the fft of that image.
B = fftshift(fft2(y)); C = log(1+abs(B));
I masked some specific pixels using C(949:1000,1102:1120)=1; But, I need to mask some random pixels. I tried using the matlab code shown in 'freehand_masking_demo.m', But I realise that it can only mask the region from an image (.tif or other format) as it needs to read the file. But, my file is not an image file it is the fft of original image.
Could you please guide me how to mask the region from 'C'?
I also tried,
maskedImage = bsxfun(@times, C, cast(burnedImage,class(C)));
With the above code I get the original image inside the masked region with blackout surrounding but I need otherway round i.e. black masked region with surrounding the original image.
I would like to thank you in advance for any help.

Answers (2)

Image Analyst
Image Analyst on 6 Nov 2015
Just skip the part of the demo where it calls imread() and reads the image from a file, and use your C variable instead.
  2 Comments
Image Analyst
Image Analyst on 9 Nov 2015
Regarding your "Answer" -- Somehow you did not integrate my demo code properly to properly mask your grayscale image. If you don't have it figured out yet, attach your code so I can fix it.
komalben shah
komalben shah on 27 Nov 2015
Hi ImageAnalyst,
Thank you for your reply and apologies for not commenting on your answer. Please find attached image and code. Thank you once again for your help.

komalben shah
komalben shah on 9 Nov 2015
Hi Image Analyst,
Thank you for your reply. Initially, I started the codes after imread() and set the grayscale = C;
The problem was in the output figures. I did get the original gray scale image, Binary mask of the region but not the image Masked with white inside region. Same for the masked black inside region. The mask is there in both images but not the original image. Eventhough it is all white, the outside region has different pixel values so there is some information but not visible. I tried with different colorbar but no luck. I have attached the .png for your reference. I tried to attach .fig file but it is 114 MB so can't upload as maximum allowed size is 5 MB
  1 Comment
Image Analyst
Image Analyst on 9 Nov 2015
This should not have been an "Answer" to your original question, but a comment to me.

Community Treasure Hunt

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

Start Hunting!