How to create a white mask?

2 次查看(过去 30 天)
Jessica
Jessica 2018-3-10
评论: Jessica 2018-3-10
I am using the below code to overlay a black, elliptical mask around an imported photo. Rather than having the imported photo surrounded by black, is there a way to change the black background color to white?
I = imread (ConvertFileName);
%# Create an ellipse shaped mask c = fix(size(I) / 2); %# Ellipse center point (y, x) r_sq = [76, 100] .^ 2; %# Ellipse radii squared (y-axis, x-axis) [X, Y] = meshgrid(1:size(I, 2), 1:size(I, 1)); ellipse_mask = (r_sq(2) * (X - c(2)) .^ 2 + r_sq(1) * (Y - c(1)) .^ 2 <= prod(r_sq));
%# Apply the mask to the image I_cropped = bsxfun(@times, I, uint8(ellipse_mask)); imshow(I_cropped)

回答(1 个)

Image Analyst
Image Analyst 2018-3-10
See my attached demo.
  1 个评论
Jessica
Jessica 2018-3-10
Thanks for uploading this. When I run the script, the background is still black. Is there a way to modify my code to just reverse the colors? The other issue is that I want to save the image with the same quality as the original image. I've been doing that with the code I pasted above with:
Filename=ConvertFileName; export_fig TempFigure.jpg -r300; B=imread('TempFigure.jpg');imwritesize(B, Filename, 2.14, 300); %Save file with 2.14 inch width and 300 dpi delete('TempFigure.jpg'); close all;

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by