在MATLAB中以灰度显示图像对比度
我试图用对比度函数将普通图片转换成灰度图像,灰度函数由两个双变量定义:x1,x1。(使用GUI) 这是我的主要职能:在MATLAB中以灰度显示图像对比度,matlab,grayscale,contrast,Matlab,Grayscale,Contrast,我试图用对比度函数将普通图片转换成灰度图像,灰度函数由两个双变量定义:x1,x1。(使用GUI) 这是我的主要职能: function varargout = EX1b(varargin) gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn'
function varargout = EX1b(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @EX1b_OpeningFcn, ...
'gui_OutputFcn', @EX1b_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function EX1b_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = EX1b_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function edit1_Callback(hObject, eventdata, handles)
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
function edit2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit3_Callback(hObject, eventdata, handles)
function edit3_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function SUBMIT_Callback(hObject, eventdata, handles)
function pushbutton1_Callback(hObject, eventdata, handles)
[filename path]=uigetfile('*.*', 'Select a file')
if(filename==0)
return
end
[img, map]= imread(fullfile(path, filename));
axes(handles.axes3) %control axes 3 (==input picture)
image(img)
axes(handles.axes7) %control axes7 (==graph)
try
x1Text = get(handles.edit2, 'string');
x2Text = get(handles.edit3, 'string');
x1Val=str2double(x1Text);
x2Val=str2double(x2Text);
grayInput = linspace(0,1);
grayOutput= setAline(grayInput, x1Val, x2Val);
plot(grayInput, grayOutput);
catch
return
end
axes(handles.axes4) %control axes 4 (==output picture)
handles.a = imread(fullfile(path, filename));
image (handles.a)
im2 = imContrast(handles.a, x1Val, x2Val);
image(im2)
axis off
这是我正在使用的两个函数:
function im2 = imContrast(im1, x1, x2)
d = 1 / (x2-x1); %distance between x1 and x2.
%display interface
im2(find(im1<=x1))=0; %range before x1 (include x1).
im2(find(im1>=x2))=1; %range after x2 (include x2).
im2(find(im1>x1 & im1 < x2)) = d * (im1(im1>x1 & im1<x2)-x1); %range from x1 to x2 (exclude x1, x2).
end
函数im2=imContrast(im1,x1,x2)
d=1/(x2-x1);%x1和x2之间的距离。
%显示界面
im2(find(im1=x2))=1;%x2之后的范围(包括x2)。
im2(find(im1>x1&im1x1&im1x1&grayInputx1&grayInput你能发布一个图像和一个我们可以运行的吗?我不确定如何..我正在使用GUI,所以有很多不必要的代码。我尝试只添加相关的代码。我只使用了任何图片,没关系,只要试着创建一个最简单的GUI来重现错误并上传代码。我尝试了..请告诉我这是否正确这就是你的意思。非常感谢你。谢谢你,我发现了问题。你能发布一个图像和一个我们可以运行的吗?我不知道怎么做。我正在使用GUI,所以有很多不必要的代码。我尝试只添加相关的代码。我只使用了任何图片,这并不重要。只要尝试创建一个最简单的GUI来复制错误并上传密码。我试过了。请告诉我这是否是你的意思。非常感谢。谢谢你,我发现了问题
function grayOutput = setAline( grayInput, x1, x2 )
line = 1 / (x2-x1); %range from x1 to x2 (exclude x1, x2)
grayOutput(find(grayInput<=x1))=0; %range before x1 (include x1)
grayOutput(find(grayInput>=x2))=1; %range after x2 (include x2)
grayOutput(find(grayInput>x1 & grayInput < x2)) = line * (grayInput(grayInput>x1 & grayInput<x2)-x1);
end