2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > matlab批量生成灰度图像_科学网—matlab彩色图像的批处理转换为灰度 二值和主成分图

matlab批量生成灰度图像_科学网—matlab彩色图像的批处理转换为灰度 二值和主成分图

时间:2023-10-24 03:38:25

相关推荐

matlab批量生成灰度图像_科学网—matlab彩色图像的批处理转换为灰度 二值和主成分图

这段代码主要用来进行图像的批处理转换为灰度、二值和主成分图图像,希望给大家借鉴。其中 RGB to bw可以直接实现,但是效果不好,所以先用RGB to gray,之后再gray to bw。RGB to PAC 涉及到三维数据转换为二维的问题。这里面涉及到数据排序的问题,需要使用到LengthSortStr函数,我以作为附件添加。由于不太熟悉科学网添加方式,所以添加的不是很好,望大家见谅。

% The RGB to gray

path='D:7-21-simplewaystems11HOG adaboost';

file='*.tif';

pic=dir([path,file]);

filename=str2mat(pic.name); %取得文件名

%调用函数

sortfile=LengthSortStr(filename);

num=size(pic,1);

image_filename='D:7-21-simplewaystems11HOG adaboost';

mkdir(image_filename,'stemsgray')

output_default_path = fullfile(image_filename,'stemsgray');

cd(output_default_path)

% message = 'Select the output folder';

% uiwait(msgbox(message));

% output_folder = uigetdir(output_default_path);

for i=1:num;

tiff{i}=imread([path,sortfile(i,:)]);

images{i}=rgb2gray(tiff{i}); % color to gray

images{i}=imadjust(images{i}); % ajusting image quality

filenames= strcat('stemsgray',num2str(i),'.tif');

imwrite(images{i},filenames)

end

% The gray to bw

clear;clc

path='D:7-21-simplewaystems11HOG adabooststemsgray';

file='*.tif';

pic=dir([path,file]);% read the number of images

filename=str2mat(pic.name); %obtain filenames

sortfile=LengthSortStr(filename);% sort function

num=size(pic,1);

image_filename='D:7-21-simplewaystems11HOG adaboost';

mkdir(image_filename,'stemsgraybw')

output_default_path = fullfile(image_filename,'stemsgraybw');

cd(output_default_path)

for i=1:num;

tiff{i}=imread([path,sortfile(i,:)]);

images{i}=im2bw(tiff{i},0.5)

filenames= strcat('wbjin',num2str(i),'.tif');

imwrite(images{i},filenames);

end

% The RGB to PCA

path='D:simplewaystemssimplywaycodebadresults';

file='*.tif';

pic=dir([path,file]);

filename=str2mat(pic.name); %取得文件名

%调用函数

sortfile=LengthSortStr(filename);

num=size(pic,1);

tiff={};

for i=1:num;

tiff{i}=imread([path,sortfile(i,:)]);

R(:,:)=tiff{i}(:,:,1); % 3D to 2D

G(:,:)=tiff{i}(:,:,2);

B(:,:)=tiff{i}(:,:,3);

[m n]=size(R);% size of 2D

R1=reshape(R,prod(size(R)),1); % Multi-row and Single-column

G1=reshape(G,prod(size(G)),1);

B1=reshape(B,prod(size(B)),1);

RGB1=[R1,G1,B1]; % three columns of RGB

[coeff,score,latent] = pca(double(RGB1));% PCA caculation

score1=score(:,1);% the first principal is selected.

% percetanges=cumsum(latent)./sum(latent);

pcaiamges{i}=reshape(score1,m,n);

pcaiamges1{i}=im2bw(pcaiamges{i})

filenames= strcat('bw',num2str(i),'.tif');

imwrite(pcaiamges1{i},filenames);

end

转载本文请联系原作者获取授权,同时请注明本文来自金秀良科学网博客。

链接地址:/blog-620863-993279.html

上一篇:matlab图像数据的调节和转换

下一篇:matlab图像数据的批处理cutting

matlab批量生成灰度图像_科学网—matlab彩色图像的批处理转换为灰度 二值和主成分图图像 - 金秀良的博文...

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。