作成した画像が元画像とサイズが異なる問題の解決方法
8 views (last 30 days)
Show older comments
以下のコードを使ってしきい値を設定した画像(しきい値画像)の作成を行っているのですが,元画像のサイズが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
0 Comments
Accepted Answer
Atsushi Ueno
on 24 Jun 2024
imwrite関数を使えば問題を回避できます。
RGB = imread('football.jpg');
maskedRGBImage = RGB; % createMask()の入出力サイズは同一なので省略
imwrite(maskedRGBImage, 'maskedRGBImage.jpg'); % しきい値画像をファイルに書き出す
clear maskedRGBImage
ImageFromFile = imread('maskedRGBImage.jpg'); % 同じファイルから読み込む
size(RGB) == size(ImageFromFile) % 元画像とファイルから読み込んだしきい値画像は同サイズか?
More Answers (0)
See Also
Categories
Find more on ビッグ データの処理 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!