Java:使用HttpClient进行POST和GET请求以及文件上传和下载

java调用下载接口下载文件 4.从HttpsURLConnection中获取文件名,在本示例中传入的参数就是文件名则不需要去获取文件名。1.设置请求头,如果需要token验证的话,也需要在请求头中设置。2.设置url地址,在get请求中,请求参数在路径中体现。3.获取url连接HttpsURLConnection。5.从HttpsURLConnection中获取输入流。6.循环读取输入流,写入输出流,将文件下载到本地。剩余的是主方法中调用的方法。二是主方法,主要流程。 阅读详情

转载自:https://blog.youkuaiyun.com/nupt123456789/article/details/42721003/

1.HttpClient

大家可以先看一下HttpClient的介绍,这篇博文写的还算不错:http://blog.youkuaiyun.com/wangpeng047/article/details/19624529

当然,详细的文档,你可以去官方网站查看和下载:http://hc.apache.org/httpclient-3.x/

2.本博客简单介绍一下POST和GET以及文件下载的应用。

代码如下:

package net.mobctrl;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

/**
 * @web http://www.mobctrl.net
 * @author Zheng Haibo
 * @Description: 文件下载 POST GET
 */
public class HttpClientUtils {

	/**
	 * 最大线程池
	 */
	public static final int THREAD_POOL_SIZE = 5;

	public interface HttpClientDownLoadProgress {
		public void onProgress(int progress);
	}

	private static HttpClientUtils httpClientDownload;

	private ExecutorService downloadExcutorService;

	private HttpClientUtils() {
		downloadExcutorService = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
	}

	public static HttpClientUtils getInstance() {
		if (httpClientDownload == null) {
			httpClientDownload = new HttpClientUtils();
		}
		return httpClientDownload;
	}

	/**
	 * 下载文件
	 * 
	 * @param url
	 * @param filePath
	 */
	public void download(final String url, final String filePath) {
		downloadExcutorService.execute(new Runnable() {

			@Override
			public void run() {
				httpDownloadFile(url, filePath, null, null);
			}
		});
	}

	/**
	 * 下载文件
	 * 
	 * @param url
	 * @param filePath
	 * @param progress
	 *            进度回调
	 */
	public void download(final String url, final String filePath,
			final HttpClientDownLoadProgress progress) {
		downloadExcutorService.execute(new Runnable() {

			@Override
			public void run() {
				httpDownloadFile(url, filePath, progress, null);
			}
		});
	}

	/**
	 * 下载文件
	 * 
	 * @param url
	 * @param filePath
	 */
	private void httpDownloadFile(String url, String filePath,
			HttpClientDownLoadProgress progress, Map<String, String> headMap) {
		CloseableHttpClient httpclient = HttpClients.createDefault();
		try {
			HttpGet httpGet = new HttpGet(url);
			setGetHead(httpGet, headMap);
			CloseableHttpResponse response1 = httpclient.execute(httpGet);
			try {
				System.out.println(response1.getStatusLine());
				HttpEntity httpEntity = response1.getEntity();
				long contentLength = httpEntity.getContentLength();
				InputStream is = httpEntity.getContent();
				// 根据InputStream 下载文件
				ByteArrayOutputStream output = new ByteArrayOutputStream();
				byte[] buffer = new byte[4096];
				int r = 0;
				long totalRead = 0;
				while ((r = is.read(buffer)) > 0) {
					output.write(buffer, 0, r);
					totalRead += r;
					if (progress != null) {// 回调进度
						progress.onProgress((int) (totalRead * 100 / contentLength));
					}
				}
				FileOutputStream fos = new FileOutputStream(filePath);
				output.writeTo(fos);
				output.flush();
				output.close();
				fos.close();
				EntityUtils.consume(httpEntity);
			} finally {
				response1.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				httpclient.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * get请求
	 * 
	 * @param url
	 * @return
	 */
	public String httpGet(String url) {
		return httpGet(url, null);
	}

	/**
	 * http get请求
	 * 
	 * @param url
	 * @return
	 */
	public String httpGet(String url, Map<String, String> headMap) {
		String responseContent = null;
		CloseableHttpClient httpclient = HttpClients.createDefault();
		try {
			HttpGet httpGet = new HttpGet(url);
			CloseableHttpResponse response1 = httpclient.execute(httpGet);
			setGetHead(httpGet, headMap);
			try {
				System.out.println(response1.getStatusLine());
				HttpEntity entity = response1.getEntity();
				responseContent = getRespString(entity);
				System.out.println("debug:" + responseContent);
				EntityUtils.consume(entity);
			} finally {
				response1.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				httpclient.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return responseContent;
	}

	public String httpPost(String url, Map<String, String> paramsMap) {
		return httpPost(url, paramsMap, null);
	}

	/**
	 * http的post请求
	 * 
	 * @param url
	 * @param paramsMap
	 * @return
	 */
	public String httpPost(String url, Map<String, String> paramsMap,
			Map<String, String> headMap) {
		String responseContent = null;
		CloseableHttpClient httpclient = HttpClients.createDefault();
		try {
			HttpPost httpPost = new HttpPost(url);
			setPostHead(httpPost, headMap);
			setPostParams(httpPost, paramsMap);
			CloseableHttpResponse response = httpclient.execute(httpPost);
			try {
				System.out.println(response.getStatusLine());
				HttpEntity entity = response.getEntity();
				responseContent = getRespString(entity);
				EntityUtils.consume(entity);
			} finally {
				response.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				httpclient.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		System.out.println("responseContent = " + responseContent);
		return responseContent;
	}

	/**
	 * 设置POST的参数
	 * 
	 * @param httpPost
	 * @param paramsMap
	 * @throws Exception
	 */
	private void setPostParams(HttpPost httpPost, Map<String, String> paramsMap)
			throws Exception {
		if (paramsMap != null && paramsMap.size() > 0) {
			List<NameValuePair> nvps = new ArrayList<NameValuePair>();
			Set<String> keySet = paramsMap.keySet();
			for (String key : keySet) {
				nvps.add(new BasicNameValuePair(key, paramsMap.get(key)));
			}
			httpPost.setEntity(new UrlEncodedFormEntity(nvps));
		}
	}

	/**
	 * 设置http的HEAD
	 * 
	 * @param httpPost
	 * @param headMap
	 */
	private void setPostHead(HttpPost httpPost, Map<String, String> headMap) {
		if (headMap != null && headMap.size() > 0) {
			Set<String> keySet = headMap.keySet();
			for (String key : keySet) {
				httpPost.addHeader(key, headMap.get(key));
			}
		}
	}

	/**
	 * 设置http的HEAD
	 * 
	 * @param httpGet
	 * @param headMap
	 */
	private void setGetHead(HttpGet httpGet, Map<String, String> headMap) {
		if (headMap != null && headMap.size() > 0) {
			Set<String> keySet = headMap.keySet();
			for (String key : keySet) {
				httpGet.addHeader(key, headMap.get(key));
			}
		}
	}

	/**
	 * 上传文件
	 * 
	 * @param serverUrl
	 *            服务器地址
	 * @param localFilePath
	 *            本地文件路径
	 * @param serverFieldName
	 * @param params
	 * @return
	 * @throws Exception
	 */
	public String uploadFileImpl(String serverUrl, String localFilePath,
			String serverFieldName, Map<String, String> params)
			throws Exception {
		String respStr = null;
		CloseableHttpClient httpclient = HttpClients.createDefault();
		try {
			HttpPost httppost = new HttpPost(serverUrl);
			FileBody binFileBody = new FileBody(new File(localFilePath));

			MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder
					.create();
			// add the file params
			multipartEntityBuilder.addPart(serverFieldName, binFileBody);
			// 设置上传的其他参数
			setUploadParams(multipartEntityBuilder, params);

			HttpEntity reqEntity = multipartEntityBuilder.build();
			httppost.setEntity(reqEntity);

			CloseableHttpResponse response = httpclient.execute(httppost);
			try {
				System.out.println(response.getStatusLine());
				HttpEntity resEntity = response.getEntity();
				respStr = getRespString(resEntity);
				EntityUtils.consume(resEntity);
			} finally {
				response.close();
			}
		} finally {
			httpclient.close();
		}
		System.out.println("resp=" + respStr);
		return respStr;
	}

	/**
	 * 设置上传文件时所附带的其他参数
	 * 
	 * @param multipartEntityBuilder
	 * @param params
	 */
	private void setUploadParams(MultipartEntityBuilder multipartEntityBuilder,
			Map<String, String> params) {
		if (params != null && params.size() > 0) {
			Set<String> keys = params.keySet();
			for (String key : keys) {
				multipartEntityBuilder
						.addPart(key, new StringBody(params.get(key),
								ContentType.TEXT_PLAIN));
			}
		}
	}

	/**
	 * 将返回结果转化为String
	 * 
	 * @param entity
	 * @return
	 * @throws Exception
	 */
	private String getRespString(HttpEntity entity) throws Exception {
		if (entity == null) {
			return null;
		}
		InputStream is = entity.getContent();
		StringBuffer strBuf = new StringBuffer();
		byte[] buffer = new byte[4096];
		int r = 0;
		while ((r = is.read(buffer)) > 0) {
			strBuf.append(new String(buffer, 0, r, "UTF-8"));
		}
		return strBuf.toString();
	}
}

我们可以使用如下代码进行测试:

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import net.mobctrl.HttpClientUtils;
import net.mobctrl.HttpClientUtils.HttpClientDownLoadProgress;

/**
 * @date 2015年1月14日 下午1:49:50
 * @author Zheng Haibo
 * @Description: 测试
 */
public class Main {

	public static void main(String[] args) {
		/**
		 * 测试下载文件 异步下载
		 */
		HttpClientUtils.getInstance().download(
				"http://newbbs.qiniudn.com/phone.png", "test.png",
				new HttpClientDownLoadProgress() {

					@Override
					public void onProgress(int progress) {
						System.out.println("download progress = " + progress);
					}
				});

		// POST 同步方法
		Map<String, String> params = new HashMap<String, String>();
		params.put("username", "admin");
		params.put("password", "admin");
		HttpClientUtils.getInstance().httpPost(
				"http://192.168.31.183:8080/SSHMySql/register", params);

		// GET 同步方法
		HttpClientUtils.getInstance().httpGet(
				"http://wthrcdn.etouch.cn/weather_mini?city=北京");

		// 上传文件 POST 同步方法
		try {
			Map<String,String> uploadParams = new LinkedHashMap<String, String>();
			uploadParams.put("userImageContentType", "image");
			uploadParams.put("userImageFileName", "testaa.png");
			HttpClientUtils.getInstance().uploadFileImpl(
					"http://192.168.31.183:8080/SSHMySql/upload", "android_bug_1.png",
					"userImage", uploadParams);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}

运行结果为:

HTTP/1.1 200 OK
responseContent = {"id":"-2","msg":"添加失败!用户名已经存在!"}
HTTP/1.1 200 OK
download progress = 6
download progress = 11
download progress = 13
download progress = 20
download progress = 22
download progress = 26
download progress = 31
download progress = 33
download progress = 35
download progress = 38
download progress = 40
download progress = 42
download progress = 44
download progress = 49
download progress = 53
download progress = 55
download progress = 57
download progress = 60
download progress = 62
download progress = 64
download progress = 66
download progress = 71
download progress = 77
download progress = 77
download progress = 80
download progress = 82
HTTP/1.1 200 OK
debug:{"desc":"OK","status":1000,"data":{"wendu":"3","ganmao":"昼夜温差很大,易发生感冒,请注意适当增减衣服,加强自我防护避免感冒。","forecast":[{"fengxiang":"无持续风向","fengli":"微风级","high":"高温 6℃","type":"晴","low":"低温 -6℃","date":"22日星期四"},{"fengxiang":"无持续风向","fengli":"微风级","high":"高温 6℃","type":"多云","low":"低温 -3℃","date":"23日星期五"},{"fengxiang":"无持续风向","fengli":"微风级","high":"高温 5℃","type":"多云","low":"低温 -3℃","date":"24日星期六"},{"fengxiang":"无持续风向","fengli":"微风级","high":"高温 5℃","type":"阴","low":"低温 -2℃","date":"25日星期天"},{"fengxiang":"无持续风向","fengli":"微风级","high":"高温 4℃","type":"多云","low":"低温 -2℃","date":"26日星期一"}],"yesterday":{"fl":"3-4级","fx":"北风","high":"高温 5℃","type":"晴","low":"低温 -6℃","date":"21日星期三"},"aqi":"124","city":"北京"}}
download progress = 84
download progress = 86
download progress = 88
download progress = 91
download progress = 93
download progress = 95
download progress = 99
download progress = 100
HTTP/1.1 200 OK
resp={"error_code":2000,"msg":"OK","filepath":"uploadfiles/192.168.31.72_android_bug_1.png"}

下载过程有进度回调。

相关的libs包,可以在如下链接中下载:http://download.youkuaiyun.com/detail/nuptboyzhb/8362801

上述代码,既可以在J2SE,J2EE中使用,也可以在Android中使用,在android中使用时,需要相关的权限。

另外,测试所使用的Web项目为:https://github.com/nuptboyzhb/SSHMySQLDemo


Httpclient发送Post、Get请求、文件上传下载 文章目录Httpclient普通Get请求带头信息的Get请求Post请求提交form表单Post请求提交Json对象Httpclient下载文件Httpclient文件上传Httpclient多文件上传全部代码httpclient Httpclient 引入maven依赖 <!-- httpclient依赖 --> <dependency> <groupId>org.apache.httpcomponents</groupId> <arti 阅读详情

相关推荐

Java使用HttpClient发送Get和Post请求

HttpClient是什么,用来干什么,怎么用?这三个问题还是看官方教程吧 英文的官方教程: http://hc.apache.org/httpcomponents-client-ga/tutorial/html/index.html 中文的官方教程: https://www.ctolib.com/topics-80581.html 需要的Jar包下载: http://hc.apach...

qq_38409944的博客 2826

Java Web 实现文件上传和下载接口功能

上传用post或者get请求都可以,这里代码中用post做的示例。

洛阳泰山的博客 7083

Apache HttpClient,一款贼强大的Java网络请求库

Apache HttpClient的介绍与使用样例

黑马非马的博客 1216

Java HTTP 接口调用三大神器实战:HttpClient+RestTemplate+Hutool HttpUtil 全解析

本文详细介绍了Apache HttpClient工具的使用方法。作为Java生态中最底层的HTTP客户端工具,HttpClient支持所有HTTP方法,提供请求头自定义、超时配置、连接池管理等高级功能,适用于复杂HTTP需求和非Spring项目。文章包含Maven依赖配置、核心API详解(如HttpGet、HttpPost等类)及完整使用步骤,并提供了GET请求的代码示例,涵盖从创建客户端到解析响应的全过程。特别强调资源关闭的重要性,避免连接泄露。该工具适合需要精细控制HTTP细节的开发场景。

qq_49474843的博客 2058

Java(114):通过HttpClient方法请求Get请求方式的下载接口

通过HttpClient方法请求Get请求方式的下载接口

fen_fen的专栏 2249

掌握HTTP GET/POST请求:Java实现与Jar包下载

POST方法是一种HTTP请求方法,用于将数据发送到服务器以创建或更新资源。它通常用于提交表单数据,上传文件,或者向服务器发送数据以供处理。与GET方法不同,POST请求不会在URL中留下痕迹,并且可以发送更大量级的数据。

weixin_31620365的博客 1083

Java通过http协议发送Get和Post请求

Java通过http协议发送Get和Post请求 本文是基于Windows 10系统环境,利用MyEclipse构建一个java项目,并通过http协议发送Get和Post请求 Windows 10 MyEclipse 一、准备工作 (1) 下载需要用的工具jar包 二、Post请求方式 (1) 将数据封装为json格式,然后再发送 /** * */ package com.inspu...

哈工大许政的博客 9万+

掌握HttpClient:发送GET、POST、PUT请求的实战技巧

GET请求是一种HTTP协议中的方法,通常用于请求服务器发送指定的资源。它是HTTP协议中最常见的方法之一,用于从指定的服务器中检索数据。GET请求通过URL参数来传递信息,其工作原理基于客户端发送一个HTTP GET请求,请求中包含所需的资源地址(URL),服务器接收请求后,解析URL参数,根据请求内容返回相应的数据。一个典型的GET请求通常由以下几部分组成:请求行(Request Line):包含了HTTP方法(GET),请求的资源路径和HTTP协议版本。

weixin_42576186的博客 1403

HttpClient发送get请求和post请求

新建两个项目:test-demo为接口方法,httpclient-demo测试发送get请求和post请求。 1.Httpclient发送get请求 httpclient-demo中测试方法 httpclient-demo中工具类 test-demo接口方法 2.Httpclient发送post请求 httpclient-demo中测试方法 Httpclient-de...

Jeffrey的博客 5376

java实现get请求post请求,文件传输

java实现get请求post请求,文件传输 /** * 发送https请求 * @param requestUrl 请求地址 * @param requestMethod 请求方式(GET、POST) * @param outputStr 提交的数据 * @return 返回微信服务器响应的信息 */

格拉姆角场(GAF)实战:用Python实现时间序列图像化处理

本文深入解析了格拉姆角场(GAF)技术,这是一种将一维时间序列转化为二维图像特征的方法,以便利用卷积神经网络(CNN)等图像模型进行深度分析。文章通过Python实战代码,详细演示了GASF和GADF两种核心转换的实现过程,并探讨了其在时序数据分类任务中的应用,为故障预警、金融模式识别等场景提供了强大的图像驱动分析视角。

weixin_29079671的博客 272

Java请求Http接口-httpClient (超详细-附带工具类)

HttpClient是Apache Jakarta Common下的子项目,用来提供高效的、最新的、功能丰富的支持HTTP协议的客户端编程工具包,并且它支持HTTP协议最新的版本和建议。HttpClient已经应用在很多的项目中,比如Apache Jakarta上很著名的另外两个开源项目Cactus和HTMLUnit都使用了HttpClient。下载地址: http://hc.apache.org/downloads.cgi。

苍煜 1万+

AMD显卡跑MiniMax H3提速30%:SageAttention ROCm适配全记录

在Transformer架构的视频生成模型中,注意力计算往往是性能瓶颈,尤其当显存资源受限时,低精度量化与内核优化成为关键突破口。SageAttention通过将QK^T矩阵乘法量化为INT8,并以FP16/INT4表达注意力概率矩阵,在保证画质的前提下显著降低访存与计算开销,相比传统FlashAttention具备更高速度上限。这一技术价值在本地部署场景尤为突出——当用户使用非NVIDIA显卡运行大型视频模型时,通用优化库常因依赖CUDA而失效。本文聚焦AMD ROCm平台下的MiniMax H3视频生成

weixin_32238157的博客 272

HttpClient使用详解 get与post请求

转自:https://www.jianshu.com/p/375be5929bed 一、HttpClient使用详解与实战一:普通的GET和POST请求 简介 HttpClient是Apache Jakarta Common下的子项目,用来提供高效的、最新的、功能丰富的支持HTTP协议的客户端编程工具包,并且它支持HTTP协议最新的版本和建议。 HttpClient最新版本是HttpClient 4.5.3 (GA)。 官方下载:http://hc.apache.org/downloads.cgi 主要

licux的博客 6383

Arduino IDE 2.3.2 配置 UNO R4 WIFI 开发环境避坑指南(附LED矩阵驱动测试)

本文详细介绍了如何在Arduino IDE 2.3.2中配置UNO R4 WIFI开发环境,并提供了LED矩阵驱动的实战指南。从开发环境搭建到硬件连接,再到LED矩阵的初始化和弹球动画实现,手把手教你避开常见配置陷阱,最终实现流畅的动画效果。特别适合刚接触UNO R4 WIFI的开发者快速上手。

weixin_28675839的博客 219

网工实验笔记:SNMP的配置

简单网络管理协议SNMP(Simple Network Management Protocol)是广泛应用于TCP/IP网络的网络管理标准协议。SNMP提供了一种通过运行网络管理软件的中心计算机(即网络管理工作站)来管理设备的方法。

2301_76170756的博客 2114

Java实现HTTP请求GET和POST之HTTPClient

文中使用的jar包有:commons-codec-1.9、commons-logging-1.2、httpclient-4.5.9、httpcore-4.4.11、httpmime-4.5.9 相关jar包下载可以直接去官网下载HTTPCLIENT的包 文中相关头信息写的不多,可以去上一篇文章“Java实现HTTP请求GET和POST之HttpURLConnection”中看 文中一些代码也...

aliaichidantong的博客 1013

基于任务的功能磁共振成像的连接性分析

虽然这种方法通过减少偶然只选择特异性代表的可能性来改善可推广性,但类别内和类别间的变异性变得更难控制(例如,"鸟类"可能是一个比"车辆"更加/不那么同质的类别),并且可能会出现关于这些预定义类别是否是现实世界实体的有意义划分的担忧——尽管这个限制在某种程度上可以通过表征相似性分析来解决。特别是,海马单变量激活和语义认知区域(左下额回)中语义信息的表征强度之间的交互预测了项目的概念记忆,而海马单变量激活和视觉处理区域(腹内侧枕叶皮层)中视觉属性的表征强度之间的交互预测了图像样本的知觉记忆。

cc1609130201的博客 2229

Java实现http(post、get)请求

package com.wolaidai.credit.management.utils; import com.alibaba.fastjson.JSON; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.http.HttpEntity;

qq_27455063的博客 1万+

优秀的 Verilog/FPGA开源项目介绍(二十六)- ISP (图像信号处理)

介绍查看《ISP算法及架构分析介绍》今天项目的顺序就是先介绍几个关于ISP算法架构的项目,包括python、matlab、c等高级语言实现的ISP算法架构,最后介绍一个FPGA实现ISP的项目。openISPhttps://github.com/cruxopen/openISP项目介绍用python实现的ISP架构,该架构涉及到的知识如下:下图是最新实现的模块:主要模块如...

OpenFPGA的博客 4946

Labview邪修01:贪吃蛇小游戏

摘要:博主使用LabVIEW 2020(32位)复刻了经典贪吃蛇游戏。程序具备随机生成蛇(初始长度3)和食物、三档速度调节、键盘方向控制等功能,碰撞边界或自身即游戏结束。实现过程包括:1)界面设计,使用二维颜色盒数组构建游戏区,添加速度枚举控件和功能按钮;2)程序架构,采用模块化设计包含Main.vi、Start.vi等6个核心VI,分别处理初始化、位置计算、碰撞检测等逻辑;3)事件驱动机制,通过开始/结束事件、按键响应和超时循环实现游戏流程控制。运行时可实时显示分数,完整还原了贪吃蛇的核心玩法。

weixin_38637405的博客 970

Java实现HttpClient发送GET、POST请求(https、http)

Java实现HttpClient发送GET、POST请求(https、http) 1、引入相关依赖包 jar包下载:httpcore4.5.5.jar fastjson-1.2.47.jar maven: &lt;dependency&gt; &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt; &lt;a...

sdx1237的博客 2887

图像处理 | 基于matlab的多尺度Retinex(MSR)和自适应直方图均衡化(CLAHE)算法联合的低照度图像增强(附代码)

本文介绍了一种基于多尺度Retinex(MSR)和CLAHE的低照度图像增强算法。算法首先对图像进行多尺度Retinex处理,通过不同尺度的高斯核去除光照影响;然后采用CLAHE算法进行对比度增强。Matlab实现展示了算法流程,包含灰度转换、多尺度Retinex增强和CLAHE处理。实验结果显示,该方法能有效提升低照度图像的可见性,增强细节表现。最后提出了改进建议,包括引入深度学习方法和优化参数选择。

尘世冰封的专栏 952
上一篇: Zookeeper相关
下一篇: HttpClient 带账号验证,post,传参为xml格式
intelrain
博客等级 码龄10年 3936粉丝 216原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值