How to create a white mask?

6 ビュー (過去 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 Center および File ExchangeConvert Image Type についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by