灰度图像时0到255之间的像素,哪个函数能把它变成0到1之间的
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了灰度图像时0到255之间的像素,哪个函数能把它变成0到1之间的相关的知识,希望对你有一定的参考价值。
参考技术A 用这个函数:void cvNormalize( const CvArr* src, CvArr* dst,double a=1, double b=0, int norm_type=CV_L2,const CvArr* mask=NULL );还有
我这个控件设定的高度是510,宽度是10,
我写了一个染色的函数,fun.
public static Bitmap fun(Bitmap Bmp)
int j=255;
int width=Bmp.width;
int Height=Bmp.Height;
BitmapData data = Bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
unsafe
byte* p = (byte*)data.Scan0;//p是位图像素首地址。
int offset = data.Stride - width *3;
for (int y =0; y <255; y = y +1)
for (int x = 0; x <10; x++)
for (int i = 0; i <12; i++)
p[i] = (byte)j;
p +=6
p += offset;
j=j-1;
Bmp.UnlockBits(data);
return Bmp;
在窗体的load事件里我调用了一下
private void Form1_Load(object sender, EventArgs e)
private Bitmap ruler= new Bitmap(MainImage.Width,MainImage.Height);
fun(ruler);
MainImage.Image = ruler;
这样实现了灰度条的功能,但是灰度条的高度不能改变,我希望可以更改灰度条的大小,并且这个更改大小后的灰度条的范围还是255到0.
这些都是我目前找到的方法本回答被提问者采纳 参考技术B 那就徐以255,不就是0到1了吗追问
算法怎么写啊?
追答这个数据用在什么方面呢,在什么软件下使用,在EXCEL中直接就是:=A1/255
图像增强基于区域相似变换函数和蜻蜓算法的灰度图像增强
图像增强是一种必要的和不可缺少的技术,增加数字的质量图像。的主要任务是生成一个新的图像中每个像素强度值使用转换函数在输入图像接收每个像素的强度值。拟议的传递函数研究被称为区域相似性传递函数(RSTF)认为密度分布相似相邻像素之间。蜻蜓算法(DA)直观的优化技术,这是首选工程应用中,已被用于优化提出了传递函数的参数值。
% Using the Regional Similarity Transformation Function and Dragonfly Algorithm.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%THIS IS A DEMO FOR NOVEL IMAGE ENHANCEMENT USING GRAV脻TAT脻ONAL SEARCH ALGORITHM
clc;
clear all;
close all;
%READ IMAGE
i=imread('test5.bmp');
i=imresize(i,1);
%--------------------------------------------------------------------------
%GLOBAL MEAN
frekans=zeros(256,1);
% It records by counting how many times each pixel value is.
for k=1:size(i,1)
for l=1:size(i,2)
value=i(k,l);
frekans(value+1)=frekans(value+1)+1;
end
end
deger=max(frekans);
for k=1:256
if deger==frekans(k)
D=k;
end
end
D=double(D/255);
image = im2double(i);
global_mean = D;
%--------------------------------------------------------------------------
% LOCAL MEAN
Bmean = mean_n(image);
%--------------------------------------------------------------------------
%SIMILARITY
[S]=similarity(i);
B=double(S);
%--------------------------
C = std_n(image,Bmean);
im_size = size(image);
%-------------------------------------------------------------------------
%OPTIMIZATION PARAMETERS
N=15; % Agent number;
Max_iteration=15;
%-------------------------------------------------------------------------
%CALL FUNCTION
[parameters Fbest BestChart MeanChart] = GSA_enhancement2(image,global_mean,B,C,im_size, N, Max_iteration);
enh = trans(i,image, B, C, global_mean, parameters(1),parameters(2),parameters(3),parameters(4) );
figure;
subplot(121)
imshow(image);
title('原图')
subplot(122)
imshow(enh);
title('GSA增强后的灰度图')
function [S]= similarity(x)
[xlen ylen] =size(x);
S=zeros(xlen, ylen);
for i=2:1:xlen-1
for j=2:1:ylen-1
%--------------------------------------------------------
%Getting the values in the mask
maskGray=zeros(1,9) ;
resim=zeros(1,9) ;
for b=1:9;
[m]=ikomsu(b,i);
[n]=jkomsu(b,j);
[res]=resimdemi(m,n,xlen,ylen);
resim(b)=res;
if(resim(b)==1)
gray= x(m,n);
maskGray (b) =gray;
else
maskGray (b) =0;
end
end
% Distance and similarity are calculated between 9 pixels in the mask and the result is determined.
DN=150;
sim=0;
sum=0;
for b=1:9
sim (b)=similarity1(maskGray(b),maskGray(9),DN);
sum=sim(b)+sum;
end
%---------------------------------------------------------
S(i,j)=sum/9;
end
end
end
%------------------------------------------------------------------------
%FUNCTIONS
%-----------------------------------------------------------------------
function [ res ] = resimdemi(x,y,w,h )
if(x<1 || x>w-1 || y<1 || y>h-1)
res=0;
else
res=1;
end
end
function [x] = ikomsu( komsuno, i)
if(komsuno ==1)
x=i-1;
elseif(komsuno ==2)
x= i;
elseif(komsuno ==3)
x= i+1;
elseif(komsuno ==4)
x= i-1;
elseif(komsuno ==5)
x= i+1;
elseif(komsuno ==6)
x= i-1;
elseif(komsuno ==7)
x= i;
elseif(komsuno ==8)
x= i+1;
elseif(komsuno ==9)
x=i;
else
x=0;
end
end
function [y] = jkomsu( komsuno, j )
if(komsuno ==1)
y= j-1;
elseif(komsuno ==2)
y= j-1;
elseif(komsuno ==3)
y= j-1;
elseif(komsuno ==4)
y= j;
elseif(komsuno ==5)
y= j;
elseif(komsuno ==6)
y= j+1;
elseif(komsuno ==7)
y= j+1;
elseif(komsuno ==8)
y= j+1;
elseif(komsuno ==9)
y= j;
else
y=0;
end
end
function [sim] = similarity1( k, o, DN)
a=0;b=0;c=0;
a=abs(k-o);
% b=(abs(l-p))^2;
% c=(abs(m-r))^2;
% //Distance calculation based on the Euclidean relation
dist=a;
% % //Calculation of similarity based on linear function
arahes=dist/DN;
sim=1 - arahes;
% sim=exp(-dist/DN);
end
完整代码添加QQ1575304183
以上是关于灰度图像时0到255之间的像素,哪个函数能把它变成0到1之间的的主要内容,如果未能解决你的问题,请参考以下文章
详解为什么OpenCV的直方图计算函数calcHist()计算出的灰度值为255的像素个数为0