作成した画像が元画像​とサイズが異なる問題​の解決方法

조회 수: 7 (최근 30일)
yoshiki
yoshiki 2024년 6월 24일
댓글: yoshiki 2024년 6월 25일
以下のコードを使ってしきい値を設定した画像(しきい値画像)の作成を行っているのですが,元画像のサイズが4000*6000なのに対し,作成した画像をfigureから保存すると667*1000になってしまいます.元画像と同サイズでしきい値画像を作成したいのですが,解決方法があればご教授して頂けると幸いです.
RGB = imread('image.jpg');
[BW,maskedRGBImage] = createMask(RGB);
imshow(maskedRGBImage,'Border','tight')
function [BW,maskedRGBImage] = createMask(RGB)
%createMask Threshold RGB image using auto-generated code from colorThresholder app.
%
% [BW,MASKEDRGBIMAGE] = createMask(RGB) thresholds image RGB using
% auto-generated code from the colorThresholder app. The colorspace and
% range for each channel of the colorspace were set within the app. The
% segmentation mask is returned in BW, and a composite of the mask and
% original RGB images is returned in maskedRGBImage.
% Auto-generated by colorThresholder app on 24-May-2024
%------------------------------------------------------
% Convert RGB image to chosen color space
I = rgb2lab(RGB);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.000;
channel1Max = 99.781;
% Define thresholds for channel 2 based on histogram settings
channel2Min = -26.783;
channel2Max = 32.161;
%channel2Max = -1.000;
% Define thresholds for channel 3 based on histogram settings
%channel3Min = -16.864;
channel3Min = 0.000;
channel3Max = 56.688;
% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
% Initialize output masked image based on input image.
maskedRGBImage = RGB;
% Set background pixels where BW is false to zero.
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;
end

채택된 답변

Atsushi Ueno
Atsushi Ueno 2024년 6월 24일
imwrite関数を使えば問題を回避できます。
RGB = imread('football.jpg');
maskedRGBImage = RGB; % createMask()の入出力サイズは同一なので省略
imwrite(maskedRGBImage, 'maskedRGBImage.jpg'); % しきい値画像をファイルに書き出す
clear maskedRGBImage
ImageFromFile = imread('maskedRGBImage.jpg'); % 同じファイルから読み込む
size(RGB) == size(ImageFromFile) % 元画像とファイルから読み込んだしきい値画像は同サイズか?
ans = 1x3 logical array
1 1 1
  댓글 수: 1
yoshiki
yoshiki 2024년 6월 25일
ありがとうございます.参考にさせていただきます.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 ビッグ データの処理에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!