필터 지우기
필터 지우기

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