How to create a white mask?

9 vues (au cours des 30 derniers jours)
Jessica
Jessica le 10 Mar 2018
Commenté : Jessica le 10 Mar 2018
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)

Réponses (1)

Image Analyst
Image Analyst le 10 Mar 2018
See my attached demo.
  1 commentaire
Jessica
Jessica le 10 Mar 2018
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;

Connectez-vous pour commenter.

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by