Borrar filtros
Borrar filtros

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

27 visualizaciones (últimos 30 días)
yoshiki
yoshiki el 24 de Jun. de 2024 a las 9:05
Comentada: yoshiki el 25 de Jun. de 2024 a las 7:47
以下のコードを使ってしきい値を設定した画像(しきい値画像)の作成を行っているのですが,元画像のサイズが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

Respuesta aceptada

Atsushi Ueno
Atsushi Ueno el 24 de Jun. de 2024 a las 14:21
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 comentario
yoshiki
yoshiki el 25 de Jun. de 2024 a las 7:47
ありがとうございます.参考にさせていただきます.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Image Processing and Computer Vision en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!